package cn.fl.capital.service.impl;

import cmm.comm.facade.framework.api.ISysCdMapApiService;
import cmm.comm.facade.framework.api.ISysDictionaryApiService;
import cmm.comm.facade.framework.api.ISysRegionApiService;
import cmm.comm.facade.framework.condition.SysCdMapDQueryCondition;
import cmm.comm.facade.framework.dto.SysCdMapDDTO;
import cmm.comm.facade.framework.dto.SysDictionaryDTO;
import cmm.comm.facade.framework.dto.SysRegionDTO;
import cmm.comm.facade.upload.api.IUploadApiService;
import cmm.comm.facade.upload.condition.SysUlDatCfgQueryCondition;
import cmm.comm.facade.upload.dto.SysUlDatCfgDTO;
import cmm.comm.facade.upload.dto.SysUlDatCfgDtlDTO;
import cmm.mid.core.framework.dto.BaseParamDTO;
import cmm.mid.core.framework.dto.DataResultDTO;
import cmm.mid.core.framework.page.DataResultVO;
import cmm.mid.core.framework.page.KeyValueVO;
import cmm.mid.core.framework.page.Pager;
import cmm.user.facade.system.api.ISysOrgApiService;
import cmm.user.facade.system.dto.SysOrgDTO;
import cn.cmm.base.framework.constant.BaseConstant;
import cn.cmm.base.framework.constant.BaseExceptionConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.logger.eum.LogExceptionEnum;
import cn.cmm.base.framework.logger.eum.LogOperEnum;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.CollectionUtils;
import cn.cmm.base.framework.utils.DateUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cn.cmm.cache.framework.utils.PropertiesCacheUtils;
import cn.fl.capital.condition.CapPayInfoQueryCondition;
import cn.fl.capital.condition.CapPayeeInfoQueryCondition;
import cn.fl.capital.constant.CapPayInfoConstant;
import cn.fl.capital.constant.CapPayeeInfoConstant;
import cn.fl.capital.constant.CapitalConstant;
import cn.fl.capital.dto.CapPayInfoDTO;
import cn.fl.capital.dto.CapPayeeInfoDTO;
import cn.fl.capital.service.ICapPayInfoApiService;
import cn.fl.capital.service.ICapPayInfoService;
import cn.fl.capital.service.ICapPayeeInfoApiService;
import cn.fl.capital.service.ICapPayeeInfoService;
import cn.fl.capital.transform.CapPayInfoVOTransform;
import cn.fl.capital.transform.CapPayeeInfoVOTransform;
import cn.fl.capital.vo.*;
import cn.fl.commons.result.ResponseData;
import cn.fl.custpay.api.ICarLoanEpidemicApiService;
import cn.fl.custpay.dto.RepaymentDTO;
import cn.fl.export.api.ICapFundExportApiService;
import cn.fl.export.condition.CapPayInfoExportCondition;
import cn.fl.fileconfig.condition.FileCfgConditonQC;
import cn.fl.flowauth.api.IPrjFlowAuthCtrlApiService;
import cn.fl.flowauth.condition.PrjFlowAuthCtrlQC;
import cn.fl.flowauth.constant.PrjFlowAuthCtrlConstant;
import cn.fl.flowauth.dto.PrjFlowAuthCtrlDTO;
import cn.fl.framework.base.constant.WebBaseConstant;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.framework.constant.DictionaryConstant;
import cn.fl.preloan.condition.PrjPrdDtlGpsQueryCondition;
import cn.fl.preloan.constants.AuditConstans;
import cn.fl.preloan.dto.audit.AuditStandingBookDTO;
import cn.fl.prjprddtlgps.service.IPrjPrdDtlGpsService;
import cn.fl.prjprddtlgps.vo.PrjPrdDtlGpsVO;
import cn.fl.project.condition.PrjPrdBscInfoQueryCondition;
import cn.fl.project.condition.PrjPrdDtlQueryCondition;
import cn.fl.project.condition.PrjPrdMtgQueryCondition;
import cn.fl.project.constant.PrjBscInfoConstant;
import cn.fl.project.constant.PrjFileInfoConstant;
import cn.fl.project.dto.PrjPrdMtgDTO;
import cn.fl.project.service.*;
import cn.fl.project.vo.*;
import cn.fl.system.constant.SysLogConstant;
import cn.fl.system.service.ISysUlDatCfgService;
import cn.fl.upload.constant.UploadConstant;
import com.alibaba.fastjson.JSON;
import fl.constant.facade.framework.constant.SysCdMapConstant;
import fl.constant.facade.framework.constant.SystemConstant;
import fl.flow.facade.flow.api.IFlowApiService;
import fl.flow.facade.flow.api.IFlowQueryApiService;
import fl.flow.facade.flow.condition.SysFlowManageVQueryCondition;
import fl.flow.facade.flow.condition.SysFlowSHQueryCondition;
import fl.flow.facade.flow.constant.FlowConstant;
import fl.flow.facade.flow.dto.FlowCompleteParamsDTO;
import fl.flow.facade.flow.dto.FlowStartParamsDTO;
import fl.flow.facade.flow.dto.SysFlowManageVDTO;
import fl.flow.facade.flow.dto.SysFlowSHDTO;
import fl.riskctrl.facade.externalinterface.service.api.IExternalAcardGpsApiService;
import fl.spl.facade.bizflow.api.ISysBizFlowRlQueryApiService;
import fl.spl.facade.bizflow.condition.SysBizFlowRlQC;
import fl.spl.facade.bizflow.dto.SysBizFlowRlDTO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * @Description: 付款信息表 客户端服务层接口实现
 * 业务层方法名称前缀：
 * 新增：add*
 * 删除：remove*
 * 修改：modify*
 * 批量：batch*
 * 查询对象：select* get*
 * 查询集合：search*
 */
@Service
public class CapPayInfoServiceImpl implements ICapPayInfoService {

    /**
     * 日志
     */
    @SuppressWarnings("unused")
    private static final Logger logger = LoggerFactory.getLogger(CapPayInfoServiceImpl.class);

    /**
     * API 暴露服务
     */
    @Autowired
    private ICapPayInfoApiService capPayInfoApiService;

    @Autowired
    private ICapPayeeInfoApiService capPayeeInfoApiService;
    /**
     * 数据字典服务
     */
    @Autowired
    private ISysDictionaryApiService sysDictionaryApiService;

    /**
     * 组织架构API
     */
    @Autowired
    private ISysOrgApiService sysOrgApiService;
    @Autowired
    private IPrjPrdDtlService prjPrdDtlService;
    @Autowired
    private IPrjPrdBscInfoService prjPrdBscInfoService;
    @Autowired
    private IUploadApiService uploadApiService;
    @Autowired
    private IFlowQueryApiService flowQueryApiService;

    /**
     * 代码映射表服务API
     */
    @Autowired
    private ISysCdMapApiService sysCdMapApiService;
    
    @Autowired
    private IFlowApiService flowApiService;

    @Autowired
    private IPrjPrdLicInfoService prjPrdLicInfoService;
    
    @Autowired
    private IPrjBscInfoService prjBscInfoService;

    @Autowired
    private ICapFundExportApiService capFundExportApiService;

    /**
     * GPS服务
     */
    @Autowired
    private IPrjPrdDtlGpsService prjPrdDtlGpsService;

    @Autowired
    private IPrjPrdVehInfoService prjPrdVehInfoService;

    @Autowired
    private ISysBizFlowRlQueryApiService sysBizFlowRlQueryApiService;

	@Autowired
	private ISysUlDatCfgService sysUlDatCfgService;
	@Autowired
	private IPrjPrdInvoiceService prjPrdInvoiceService;

	@Autowired
    ISysRegionApiService sysRegionApiService;

	@Autowired
	private IPrjFlowAuthCtrlApiService prjFlowAuthCtrlService;

	@Autowired
	private ICapPayeeInfoService capPayeeInfoService;

	@Autowired
	private ICarLoanEpidemicApiService carLoanEpidemicApiService;

	@Autowired
	IExternalAcardGpsApiService externalAcardGpsApiService;

	@Autowired
	private IProjectApiService projectApiService;

	@Override
    public CapPayInfoVO selectById(Long id) throws BaseException {
        if (StringUtils.isEmpty(id)) return null;
        CapPayInfoDTO dto = this.capPayInfoApiService.selectCapPayInfoById(id);
        CapPayInfoVO vo = CapPayInfoVOTransform.toVO(dto);
        if (vo != null && !CapitalConstant.CODE_CAP_PAY_STS_CD_1.equals(vo.getPayStsCd())) {
            //查询放款流程信息
            SysFlowSHQueryCondition condition = new SysFlowSHQueryCondition();
            condition.setSysCd(CurrentThreadContext.getCurrentSysCd());
            condition.setDataId(id);
            condition.setWordsInTheTable(CapPayInfoConstant.CAP_FLOW_S_H_CAP);
            condition.setpInstId(vo.getPrInsId());
            condition.setStatus(1);
            List<SysFlowSHDTO> flowSHDTOList = flowQueryApiService.searchFlowSHList(condition);
            if (CollectionUtils.isNotEmpty(flowSHDTOList)) {
                SysFlowSHDTO flowSHDTO = flowSHDTOList.get(0);
                vo.setFlowStartTm(flowSHDTO.getpCrtTm());//流程创建时间
				vo.setProcDefKey(flowSHDTO.getPDefKey());
            }
        }
        List<CapPayInfoVO> voList = new ArrayList<>();
        voList.add(vo);
        this.setDictData(voList);
        return voList.get(0);
    }

    @Override
    public Long add(CapPayInfoVO entity) throws BaseException {
        if (null == entity) return null;
        return this.capPayInfoApiService.addCapPayInfo(CapPayInfoVOTransform.toDTO(entity));
    }

    @Override
    public boolean removeByIds(List<Long> ids) throws BaseException {
        if (CollectionUtils.isEmpty(ids)) return false;
        return this.capPayInfoApiService.removeCapPayInfoByIds(ids, CurrentThreadContext.getCurrentUserId());
    }

    @Override
    public boolean modify(CapPayInfoVO entity) throws BaseException {
        if (null == entity) return false;
        return this.capPayInfoApiService.modifyCapPayInfo(CapPayInfoVOTransform.toDTO(entity));
    }

    /***********************************
     * 付款申请
     * @param entity
     * @return
     * @throws BaseException
     ************************************/
    @Override
    public DataResultVO payApply(CapPayInfoVO entity) throws BaseException {
        DataResultVO resultVO = null;

        //获取发起流程对象
        CapPayFlowCfgParmVO parmVO = new CapPayFlowCfgParmVO();
        parmVO.setPayTypCd(entity.getPayTypCd());
        parmVO.setCstMgrOrgCd(entity.getCstMgrOrgCd());
		parmVO.setBuOrgCd(entity.getBuOrgCd());
        //流程定义key
        if(StringUtils.isNotBlank(entity.getFlowKey())){
        	parmVO.setProcDefKey(entity.getFlowKey());
		}
        //是否新车
        PrjPrdBscInfoVO prjPrdBscInfoDTO = this.prjPrdBscInfoService.selectById(entity.getPrjPrdId());
        if(null != prjPrdBscInfoDTO){
            parmVO.setIsNewPrd(prjPrdBscInfoDTO.getIsNew());
        }
        //项目类型
        CapPayInfoVO capPayInfoVO = this.selectById(entity.getId());
        //PrjBscInfoVO prjBscInfoVO = this.prjBscInfoService.selectById(entity.getPrjId());
        if(null != capPayInfoVO){
        	parmVO.setPrjTypCd(capPayInfoVO.getPrjTypCd());
			//客户经理信息：CST_MGR_ID,CST_MGR_NM,CST_MGR_ORG_CD,BU_ORG_CD
			parmVO.setCstMgrId(capPayInfoVO.getCstMgrId());
			parmVO.setCstMgrNm(capPayInfoVO.getCstMgrNm());
			if (StringUtils.isBlank(parmVO.getCstMgrOrgCd())) {
				parmVO.setCstMgrOrgCd(capPayInfoVO.getCstMgrOrgCd());
			}
			if (StringUtils.isEmpty(parmVO.getBuOrgCd())) {
				parmVO.setBuOrgCd(capPayInfoVO.getBuOrgCd());
			}
        }
		if (parmVO.getCstMgrId() == null) {
			parmVO.setCstMgrId(CurrentThreadContext.getCurrentUserId());
		}
		if (StringUtils.isEmpty(parmVO.getCstMgrNm())) {
			parmVO.setCstMgrNm(CurrentThreadContext.getCurrentUserName());
		}
		if (StringUtils.isBlank(parmVO.getCstMgrOrgCd())) {
			parmVO.setCstMgrOrgCd(CurrentThreadContext.getCurrentOrgCd());
		}
		if (StringUtils.isEmpty(parmVO.getBuOrgCd())) {
			parmVO.setBuOrgCd(CurrentThreadContext.getCurrentBuOrgCd());
		}

        FlowStartParamsDTO paramsDTO = getFlowStartObj(parmVO);
        
        //17-9-11 by YAOXIURONG 汽车金融二手车放款流程 发起校验上牌
        if(StringUtils.isNotEmpty(entity.getPrjPrdDtlId())
        		&& StringUtils.isNotEmpty(paramsDTO.getProcDefKey()) && paramsDTO.getProcDefKey().equals("FLOW_00000005_002_002")){
        	BaseLogUtils.info(logger, "payApply", "===查询上牌信息Start===prjPrdDtlId:"+entity.getPrjPrdDtlId());
    		PrjPrdLicInfoVO prjPrdLicInfoVO = this.prjPrdLicInfoService.selectById(entity.getPrjPrdDtlId());
    		BaseLogUtils.info(logger, "payApply", "===查询上牌信息End===prjPrdLicInfoDTO:"+JSON.toJSONString(prjPrdLicInfoVO));
    		if(null==prjPrdLicInfoVO){
    			resultVO = new DataResultVO(BaseConstant.IS_YESNO_NO, "上牌信息未维护,请先维护上牌信息!");
    			return  resultVO;
    		}
        }
        //发起放款流程后校验 GPS是否有资产绑定 有的话 不能发起流程
        PrjPrdDtlGpsQueryCondition condition = new PrjPrdDtlGpsQueryCondition();
        condition.setIsDel(0);
        condition.setPrjDtlId(capPayInfoVO.getPrjPrdDtlId());
        BaseLogUtils.info(logger, "searchList", "查询GPS请求参数是"+JSON.toJSONString(condition));
        List<PrjPrdDtlGpsVO> searchList = prjPrdDtlGpsService.searchList(condition);
        BaseLogUtils.info(logger, "searchList", "查询GPS返回结果是"+JSON.toJSONString(searchList));

        if(!CollectionUtils.isEmpty(searchList)){
        	for (PrjPrdDtlGpsVO dto : searchList) {
    			//获取GPS状态
        		/*String audStsCd = dto.getAudStsCd();
        		if(StringUtils.isNotEmpty(audStsCd)&&(!audStsCd.equals("0"))){
        			 resultVO = new DataResultVO(BaseConstant.IS_YESNO_NO, "当前资产GPS信息已在真实资产上绑定,请调整后发起!");
        			 return resultVO;
        		}*/
        		Integer ret = prjPrdDtlGpsService.checkGPSExist(dto.getGpsCardNo(), capPayInfoVO.getPrjPrdDtlId());
        		if(ret!=1){
        			 resultVO = new DataResultVO(BaseConstant.IS_YESNO_NO, "当前资产GPS信息已在真实资产上绑定,请调整后发起!");
        			 return resultVO;
        		}
    		}

        }
		//校验当前用户是否被限制
		PrjFlowAuthCtrlQC strlQc = new PrjFlowAuthCtrlQC();
		strlQc.setIsValid(1);
		strlQc.setPassiveCtrlId(CurrentThreadContext.getCurrentUserId());
		strlQc.setFlowStartTm(DateUtils.formatDateToString(new Date(), "yyyy-MM-dd HH:mm:ss"));
		strlQc.setCtrlPrjTypCd(capPayInfoVO.getPrjTypCd());
		strlQc.setCtrlContent(PrjFlowAuthCtrlConstant.CTRL_CONTENT_2);
		BaseLogUtils.newLogger("isPrjFlowAuthCtrl.查询项目流程权限控制.入参qc=" + com.alibaba.fastjson.JSONObject.toJSONString(strlQc)).info();
		List<PrjFlowAuthCtrlDTO> prjFlowAuthCtrlDTOS = prjFlowAuthCtrlService.searchList(strlQc);
		BaseLogUtils.newLogger("isPrjFlowAuthCtrl.查询项目流程权限控制.result=" + prjFlowAuthCtrlDTOS.size()).info();
		if (CollectionUtils.isNotEmpty(prjFlowAuthCtrlDTOS) && prjFlowAuthCtrlDTOS.size() > 0) {
			for (PrjFlowAuthCtrlDTO prjFlowAuthCtrlDTO : prjFlowAuthCtrlDTOS) {
				if (StringUtils.isNotEmpty(CurrentThreadContext.getCurrentOrgCd()) && CurrentThreadContext.getCurrentOrgCd().startsWith(prjFlowAuthCtrlDTO.getPassiveCtrlOrgCd())) {
					throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_601, "由于权限控制，无法发起放款流程！");
				}
			}
		}

        //修改放款，发起放款流程
        DataResultDTO resultDTO = this.capPayInfoApiService.modifyCapPayInfo(CapPayInfoVOTransform.toDTO(entity), paramsDTO);
        if (resultDTO != null) {
            resultVO = new DataResultVO(Integer.parseInt(resultDTO.getCode()), resultDTO.getInfo());

			//修改GPS的状态为审核中 by lgj
//			PrjPrdDtlGpsDTO dto = new PrjPrdDtlGpsDTO();
//			//dto.setId(capPayInfoVO.getPrjPrdDtlId());
//			dto.setPrjDtlId(capPayInfoVO.getPrjPrdDtlId());
//			dto.setIsDel(0);
//			dto.setAudStsCd("1");
			BaseLogUtils.info(logger, "updatePrjPrdDtlGps", "发起放款流程成功后修改GPS请求参数是,audstscd=1 dtlid="+capPayInfoVO.getPrjPrdDtlId());
			boolean ret = prjPrdDtlGpsService.modifyGpsAudStsByDtlId(1,capPayInfoVO.getPrjPrdDtlId());
			BaseLogUtils.info(logger, "updatePrjPrdDtlGps", "发起放款流程成功后修改GPS返回结果是"+JSON.toJSONString(ret));
            
            //修改合格状态为审核中
            //获取项目产品明细表
            PrjPrdDtlVO prjPrdDtlVO = prjPrdDtlService.selectById(capPayInfoVO.getPrjPrdDtlId());
            BaseLogUtils.info(logger, "modify", "发起放款流程成功后修改合格证状态请求参数是:"+capPayInfoVO.getPrjPrdDtlId());
			boolean vehRet = prjPrdVehInfoService.modifyPrjPrdVehAudStsCdByDtlId(capPayInfoVO.getPrjPrdDtlId(),FlowConstant.FLOW_CHECK_STATE_IN);
            BaseLogUtils.info(logger, "modify", "发起放款流程成功后修改合格证状态返回结果是:"+vehRet);

			//修改发票状态为审核中
			BaseLogUtils.info(logger, "isModify", "发起放款流程成功后修改发票状态请求参数是 prjId="+prjPrdDtlVO.getPrjId()+" paySchNo="+prjPrdDtlVO.getPaySchNo());
			boolean flag = prjPrdInvoiceService.modifyAudStsByPrjIdAndPaySchNo(prjPrdDtlVO.getPrjId().toString(),prjPrdDtlVO.getPaySchNo(),FlowConstant.FLOW_CHECK_STATE_IN);
			BaseLogUtils.info(logger, "isModify", "发起放款流程成功后修改发票状态返回结果是"+flag);
//			PrjPrdInvoiceQueryCondition invoiceQueryCondition = new PrjPrdInvoiceQueryCondition();
//			invoiceQueryCondition.setPrjId(prjPrdDtlVO.getPrjId().toString());
//			invoiceQueryCondition.setPaySchNo(prjPrdDtlVO.getPaySchNo());
//			List<PrjPrdInvoiceVO> prjPrdInvoiceList = prjPrdInvoiceService.searchPrjPrdInvoiceList(invoiceQueryCondition);
//			if (CollectionUtils.isNotEmpty(prjPrdInvoiceList)) {
//				for (PrjPrdInvoiceVO prjPrdInvoiceVO : prjPrdInvoiceList) {
//					prjPrdInvoiceVO.setAudStsCd(FlowConstant.FLOW_CHECK_STATE_IN);
//					BaseLogUtils.info(logger, "isModify", "发起放款流程成功后修改发票状态请求参数是"+JSON.toJSONString(prjPrdInvoiceVO));
//					boolean isModify = prjPrdInvoiceService.modify(prjPrdInvoiceVO);
//
//				}
//			}
        } else {
            resultVO = new DataResultVO(BaseConstant.IS_YESNO_NO, "流程发起失败");
        }
        return resultVO;
    }
    /***********************************
     * 付款申请  17-8-9 by YAOXIURONG
     * @param entity
     * @return
     * @throws BaseException
     ************************************/
    @Override
    public DataResultVO payApplyV2(DataResultVO result, CapPayInfoVO entity, String procDefKey) throws BaseException {
    	CapPayFlowCfgParmVO parmVO = new CapPayFlowCfgParmVO();
    	parmVO.setProcDefKey(procDefKey);
    	parmVO.setPayTypCd(entity.getPayTypCd());
    	parmVO.setCstMgrOrgCd(entity.getCstMgrOrgCd());
    	if(StringUtils.isBlank(entity.getCstMgrOrgCd())){
    		parmVO.setCstMgrOrgCd(CurrentThreadContext.getCurrentOrgCd());
    	}
    	PrjPrdBscInfoVO prjPrdBscInfoDTO = this.prjPrdBscInfoService.selectById(entity.getPrjPrdId());
    	if(null != prjPrdBscInfoDTO){
    		parmVO.setIsNewPrd(prjPrdBscInfoDTO.getIsNew());//是否新车
    		parmVO.setSplId(prjPrdBscInfoDTO.getSplId());//供应商ID
    	}
    	PrjPrdDtlVO prjPrdDtlVO = this.prjPrdDtlService.selectById(entity.getPrjPrdDtlId());
    	if(null!=prjPrdDtlVO){
    		parmVO.setLnkCompId(prjPrdDtlVO.getLnkCompId());//挂靠公司ID
    	}
    	//项目类型
        PrjBscInfoVO prjBscInfoVO = this.prjBscInfoService.selectById(entity.getPrjId());
        if(null != prjBscInfoVO){
        	parmVO.setPrjTypCd(prjBscInfoVO.getPrjTypCd());
        }
    	
    	//获取流程发起对象
		result = this.getFlowStartObjV2(parmVO, result);
		if(BaseConstant.IS_YESNO_YES==result.getSuccess()){
			FlowStartParamsDTO flowStartParamsDTO = (FlowStartParamsDTO) result.getData();
			
			//17-9-11 by YAOXIURONG 汽车金融二手车放款流程 发起校验上牌
	        if(StringUtils.isNotEmpty(entity.getPrjPrdDtlId())
	        		&& StringUtils.isNotEmpty(flowStartParamsDTO.getProcDefKey()) && flowStartParamsDTO.getProcDefKey().equals("FLOW_00000005_002_002")){
	        	BaseLogUtils.info(logger, "payApply", "===查询上牌信息Start===prjPrdDtlId:"+entity.getPrjPrdDtlId());
	    		PrjPrdLicInfoVO prjPrdLicInfoVO = this.prjPrdLicInfoService.selectById(entity.getPrjPrdDtlId());
	    		BaseLogUtils.info(logger, "payApply", "===查询上牌信息End===prjPrdLicInfoDTO:"+JSON.toJSONString(prjPrdLicInfoVO));
	    		if(null==prjPrdLicInfoVO){
	    			result = new DataResultVO(BaseConstant.IS_YESNO_NO, "上牌信息未维护,请先维护上牌信息!");
	    			return  result;
	    		}
	        }
			
			//修改放款，发起放款流程
			DataResultDTO dataResultDTO = this.capPayInfoApiService.modifyCapPayInfo(CapPayInfoVOTransform.toDTO(entity), flowStartParamsDTO);
			if (dataResultDTO != null) {
				result = new DataResultVO(Integer.parseInt(dataResultDTO.getCode()), dataResultDTO.getInfo());
	    	} else {
	    		result = new DataResultVO(BaseConstant.IS_YESNO_NO, "流程发起失败");
	    	}
			return result;
		}else{
			return result;
		}
    }
    
    /**
     * 获取流程发起参数对象
     * @param capPayFlowCfgParmVO
     * @param result
     * @return
     * @throws BaseException
     * @author YAOXIURONG 17-8-9
     */
    private DataResultVO getFlowStartObjV2(CapPayFlowCfgParmVO capPayFlowCfgParmVO, DataResultVO result)throws BaseException{
    	BaseLogUtils.info(logger, "getFlowStartObjV2", 
    			"===获取流程发起参数对象Start===capPayFlowCfgParmVO:"+JSON.toJSONString(capPayFlowCfgParmVO)+",result:"+JSON.toJSONString(result), 
    			CurrentThreadContext.getCurrentUserName());
    	if(null==capPayFlowCfgParmVO || StringUtils.isEmpty(capPayFlowCfgParmVO.getPayTypCd())){
    		throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "付款类型不能为空.");
    	}
    	if(StringUtils.isEmpty(capPayFlowCfgParmVO.getPayTypCd())){
    		throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "客户经理组织架构不能为空.");
    	}
    	String payTypCd = capPayFlowCfgParmVO.getPayTypCd();//付款类型 
    	Integer isNewPrd = capPayFlowCfgParmVO.getIsNewPrd();//是否新车
    	String cstMgrOrgCd = capPayFlowCfgParmVO.getCstMgrOrgCd();//客户经理组织架构 
    	String prjTypCd = capPayFlowCfgParmVO.getPrjTypCd();//项目类型
    	
    	//根据付款类型获取流程业务分类
    	String modelTyp = this.getFlowModelTyp(payTypCd, CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd());
    	if (StringUtils.isEmpty(modelTyp)) {
    		throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "流程业务分类不能为空");
    	}
    	
    	//流程定义KEY
    	String procDefKey = capPayFlowCfgParmVO.getProcDefKey();
    	if(StringUtils.isEmpty(capPayFlowCfgParmVO.getProcDefKey())){
    		//0.项目类型|放款类型
    		if(StringUtils.isNotEmpty(prjTypCd)){
    			StringBuffer sCode = new StringBuffer();
				sCode.append(prjTypCd);
				sCode.append("|");
				sCode.append(payTypCd);
    			List<SysCdMapDDTO> sysCdMapDDTOList = this.getProcDefKey(cstMgrOrgCd, PropertiesCacheUtils.getProperty(SysCdMapConstant.M_TYP_CD_PAY_PRJ_TYP_CD), sCode.toString());
    			if(CollectionUtils.isNotEmpty(sysCdMapDDTOList) && sysCdMapDDTOList.size()==1){
    				SysCdMapDDTO sysCdMapDDTO = sysCdMapDDTOList.get(0);
    				procDefKey = sysCdMapDDTO.getTCode();
    			}
    		}
    		if(StringUtils.isNotEmpty(prjTypCd) && prjTypCd.equals(PrjBscInfoConstant.PRJ_TYP_CD_GHKD) && StringUtils.isEmpty(procDefKey)){
    			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_604, "未找到要发起的流程.");
    		}
    		if(StringUtils.isNotEmpty(prjTypCd) && prjTypCd.equals(PrjBscInfoConstant.CODE_PRJ_TYP_CD_BILLING_CD) && StringUtils.isEmpty(procDefKey)){
    			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_604, "未找到要发起的流程.");
    		}
    		
    		//1.根据参数查找配置 - 是否新车|放款类型
			if(StringUtils.isEmpty(procDefKey)){
				if(StringUtils.isNotEmpty(isNewPrd)){
					StringBuffer sCode = new StringBuffer();
					sCode.append(isNewPrd);
					sCode.append("|");
					sCode.append(payTypCd);
					List<SysCdMapDDTO> sysCdMapDDTOList = this.getProcDefKey(cstMgrOrgCd, PropertiesCacheUtils.getProperty(SysCdMapConstant.M_TYP_CD_PAY_TYP_CD), sCode.toString());
					if(CollectionUtils.isNotEmpty(sysCdMapDDTOList) && sysCdMapDDTOList.size()==1){
						SysCdMapDDTO sysCdMapDDTO = sysCdMapDDTOList.get(0);
						procDefKey = sysCdMapDDTO.getTCode();
					}
				}
			}
    		//2.配置里没有  按架构查询所有符合要求的
    		if(StringUtils.isEmpty(procDefKey)){
    			//查询当前组织架构所有立项流程
				SysFlowManageVQueryCondition flowManaQC = new SysFlowManageVQueryCondition();
				flowManaQC.setSysCd(CurrentThreadContext.getCurrentSysCd());
				flowManaQC.setIsDel(BaseConstant.IS_YESNO_NO);
				flowManaQC.setIsValid(BaseConstant.IS_YESNO_YES);
				flowManaQC.setModelTyp(modelTyp);
				flowManaQC.setOrgCd(cstMgrOrgCd);
				BaseLogUtils.info(logger, "addFlowStart", "===查询客户经理组织架构下放款流程Start===flowManaQC:"+JSON.toJSONString(flowManaQC));
				List<SysFlowManageVDTO> sysFlowManageVDTOList = this.flowApiService.searchFlowManageVListForStart(flowManaQC);
				BaseLogUtils.info(logger, "addFlowStart", "===查询客户经理组织架构下放款流程End===sysFlowManageVDTOList:"+JSON.toJSONString(sysFlowManageVDTOList));
				if(CollectionUtils.isNotEmpty(sysFlowManageVDTOList) && sysFlowManageVDTOList.size()==1){
					SysFlowManageVDTO sysFlowManageVDTO = sysFlowManageVDTOList.get(0);
					procDefKey = sysFlowManageVDTO.getProcDefKey();
				}else if(CollectionUtils.isNotEmpty(sysFlowManageVDTOList) && sysFlowManageVDTOList.size()>1){
					result.setSuccess(2);
					com.alibaba.fastjson.JSONArray resultArray = new com.alibaba.fastjson.JSONArray();
					for (SysFlowManageVDTO sysFlowManageVDTO : sysFlowManageVDTOList) {
						com.alibaba.fastjson.JSONObject obj = new com.alibaba.fastjson.JSONObject();
						obj.put("procDefKey", sysFlowManageVDTO.getProcDefKey());//流程KEY
						obj.put("procNm", sysFlowManageVDTO.getProcDefNm());//流程名称
						resultArray.add(obj);
					}
					result.setData(resultArray);
					return result;
				}else{
					result.setSuccess(BaseConstant.IS_YESNO_NO);
					result.setInfo("未找到能发起的流程.");
					return result;
				}
    		}
    	}
    	
    	if(StringUtils.isEmpty(procDefKey)){
    		result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("流程发起失败,未找到要发起的流程.");
    	}else{
    		//3.重卡事业部需  校验此流程KEY  在此放款数据关联的供应商/挂靠公司下是否有权限发起
    		String buOrgCd = CurrentThreadContext.getCurrentBuOrgCd();
    		if(StringUtils.isNotEmpty(cstMgrOrgCd) && cstMgrOrgCd.length()>=8){
    			buOrgCd = cstMgrOrgCd.substring(0, 8);
    		}
    		if(StringUtils.isNotEmpty(procDefKey) && PropertiesCacheUtils.getProperty(SystemConstant.FL_ZK_BU_ORG_CD).equals(buOrgCd)){
    			//校验供应商流程权限
    			if(StringUtils.isNotEmpty(capPayFlowCfgParmVO.getSplId())){
    				SysBizFlowRlQC sysBizFlowRlQC = new SysBizFlowRlQC();
                    sysBizFlowRlQC.setDataId(capPayFlowCfgParmVO.getSplId());
                    sysBizFlowRlQC.setTabNm("SPL_BSC_INFO");
    				List<SysBizFlowRlDTO> dtoList = this.sysBizFlowRlQueryApiService.searchList(sysBizFlowRlQC);
    				if(CollectionUtils.isEmpty(dtoList)){
    					result.setSuccess(BaseConstant.IS_YESNO_NO);
    					result.setInfo("产品供应商不支持此流程["+procDefKey+"].");
    					return result;
    				}else{
    					List<String> procDefKeyList = new ArrayList<String>();
    					for (SysBizFlowRlDTO sysBizFlowRlDTO : dtoList) {
    						procDefKeyList.add(sysBizFlowRlDTO.getPDefKey());
						}
    					if(!procDefKeyList.contains(procDefKey)){
    						result.setSuccess(BaseConstant.IS_YESNO_NO);
    						result.setInfo("产品供应商不支持此流程["+procDefKey+"].");
        					return result;
    					}
    				}
    			}
    			//校验挂靠公司流程权限
    			if(StringUtils.isNotEmpty(capPayFlowCfgParmVO.getLnkCompId())){
                    SysBizFlowRlQC sysBizFlowRlQC = new SysBizFlowRlQC();
                    sysBizFlowRlQC.setDataId(capPayFlowCfgParmVO.getLnkCompId());
                    sysBizFlowRlQC.setTabNm("PRJ_LNK_COMP");
    				List<SysBizFlowRlDTO> dtoList = this.sysBizFlowRlQueryApiService.searchList(sysBizFlowRlQC);
    				if(CollectionUtils.isEmpty(dtoList)){
    					result.setSuccess(BaseConstant.IS_YESNO_NO);
    					result.setInfo("产品挂靠公司不支持此流程["+procDefKey+"].");
    					return result;
    				}else{
    					List<String> procDefKeyList = new ArrayList<String>();
    					for (SysBizFlowRlDTO sysBizFlowRlDTO : dtoList) {
    						procDefKeyList.add(sysBizFlowRlDTO.getPDefKey());
    					}
    					if(!procDefKeyList.contains(procDefKey)){
    						result.setSuccess(BaseConstant.IS_YESNO_NO);
    						result.setInfo("产品挂靠公司不支持此流程["+procDefKey+"].");
    						return result;
    					}
    				}
    			}
    		}
    		
    		FlowStartParamsDTO flowStartParamsDTO = new FlowStartParamsDTO();
    		flowStartParamsDTO.setProcDefKey(procDefKey);
    		flowStartParamsDTO.setAudStsCd(FlowConstant.FLOW_CHECK_STATE_IN);
    		flowStartParamsDTO.setWordsInTheTable(CapPayInfoConstant.CAP_FLOW_S_H_CAP);
    		flowStartParamsDTO.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
    		flowStartParamsDTO.setOrgCd(CurrentThreadContext.getCurrentOrgCd());
    		flowStartParamsDTO.setSysCd(CurrentThreadContext.getCurrentSysCd());
    		flowStartParamsDTO.setBuOrgCd(CurrentThreadContext.getCurrentBuOrgCd());
    		flowStartParamsDTO.setInitiator(String.valueOf(CurrentThreadContext.getCurrentUserId()));
    		flowStartParamsDTO.setInitiatorNm(CurrentThreadContext.getCurrentUserName());
    		flowStartParamsDTO.setProcPriority(FlowConstant.FLOW_PRIORITY_EMERGENCY);
    		flowStartParamsDTO.setBusinessType(FlowConstant.FLOW_BUSINESS_TYP_CAP_PAY_INFO);
    		flowStartParamsDTO.setModelTyp(modelTyp);
    		
    		//根据流程KEY查询流程版本
    		SysFlowManageVQueryCondition flowManaQC = new SysFlowManageVQueryCondition();
    		flowManaQC.setSysCd(CurrentThreadContext.getCurrentSysCd());
    		flowManaQC.setIsDel(BaseConstant.IS_YESNO_NO);
    		flowManaQC.setIsValid(BaseConstant.IS_YESNO_YES);
    		flowManaQC.setModelTyp(modelTyp);
    		flowManaQC.setOrgCd(cstMgrOrgCd);
    		flowManaQC.setProcDefKey(procDefKey);
    		List<SysFlowManageVDTO> flowManageVListForStart = this.flowApiService.searchFlowManageVListForStart(flowManaQC);
    		if(CollectionUtils.isNotEmpty(flowManageVListForStart) && flowManageVListForStart.size()==1){
    			SysFlowManageVDTO sysFlowManageVDTO = flowManageVListForStart.get(0);
    			flowStartParamsDTO.setProcDefId(sysFlowManageVDTO.getProcDefId());
    			flowStartParamsDTO.setProcDefKey(sysFlowManageVDTO.getProcDefKey());
    			flowStartParamsDTO.setProcNo(sysFlowManageVDTO.getProcNo());
    			result.setSuccess(BaseConstant.IS_YESNO_YES);
    			result.setData(flowStartParamsDTO);
    		}else{
    			result.setSuccess(BaseConstant.IS_YESNO_NO);
    			result.setInfo("流程发起失败,未找到要发起的流程或流程版本不唯一.");
    		}
    	}
    	BaseLogUtils.info(logger, "getFlowStartObjV2", "===获取流程发起参数对象End===result:"+JSON.toJSONString(result), 
    			CurrentThreadContext.getCurrentUserName());
		return result;
    }

    @Override
    public Pager searchListPage(Pager page) throws BaseException {
        CapPayInfoQueryCondition condition = null;
        if (null == page) {
            page = new Pager();
            page.setCondition(new CapPayInfoQueryCondition());
        }
        condition = (CapPayInfoQueryCondition) page.getCondition();
        condition.setSysCd(CurrentThreadContext.getCurrentSysCd());//当前系统代码
        condition.setOrgCd(CurrentThreadContext.getCurrentOrgCd());//当前机构代码
        condition.setUsrId(CurrentThreadContext.getCurrentUserId());//当前用户ID
        BaseLogUtils.info(logger, "searchListPage", "cappayinfo request="+JSON.toJSONString(condition.getRgnCityCd()),CurrentThreadContext.getCurrentUserName());
        page = this.capPayInfoApiService.searchCapPayInfoListPage(page);
        if (CollectionUtils.isNotEmpty(page.getResultList())) {
			List<CapPayInfoDTO> tmp = (List<CapPayInfoDTO>)page.getResultList();
			BaseLogUtils.info(logger, "searchListPage", "cappayinfo return"+JSON.toJSONString(tmp),CurrentThreadContext.getCurrentUserName());

            List<CapPayInfoVO> voList = CapPayInfoVOTransform.toVOList((List<CapPayInfoDTO>) page.getResultList());
            this.setDictData(voList);
            page.setResultList(voList);
        }
        return page;
    }

    @Override
    public List<CapPayInfoVO> searchList(CapPayInfoQueryCondition condition) throws BaseException {
        if (null == condition) condition = new CapPayInfoQueryCondition();
        condition.setSysCd(CurrentThreadContext.getCurrentSysCd());//当前系统代码
        condition.setOrgCd(CurrentThreadContext.getCurrentOrgCd());//当前机构代码
        condition.setUsrId(CurrentThreadContext.getCurrentUserId());//当前用户ID
        List<CapPayInfoVO> voList = CapPayInfoVOTransform.toVOList(this.capPayInfoApiService.searchCapPayInfoList(condition));
        this.setDictData(voList);
        return voList;
    }

    /**
     * 付款状态
     *
     * @return
     * @throws BaseException
     */
    @Override
    public List<KeyValueVO> getPayStsCdList() throws BaseException {
        return this.sysDictionaryApiService.getKvList(CapPayInfoConstant.CODE_PAY_STS_CD, CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd());
    }

    /**
     * 申请来源
     *
     * @return
     * @throws BaseException
     */
    @Override
    public List<KeyValueVO> getApplyResCdList() throws BaseException {
    	return this.sysDictionaryApiService.getKvList(CapPayInfoConstant.CODE_APPLY_RES_CD, CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd());
    }
    
    /**
     * 首期款代收状态
     *
     * @return
     * @throws BaseException
     */
    @Override
    public List<KeyValueVO> getFstColCdList() throws BaseException {
        return this.sysDictionaryApiService.getKvList(CapPayInfoConstant.CODE_FST_COL_CD, CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd());
    }

    /**
     * 收款方类型
     *
     * @return
     * @throws BaseException
     */
    public List<KeyValueVO> getPayeeTypCdList() throws BaseException {
        return this.sysDictionaryApiService.getKvList(CapPayInfoConstant.CODE_PAYEE_TYP_CD, CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd());
    }

    /**
     * 款项
     *
     * @return
     * @throws BaseException
     */
    public List<KeyValueVO> getFundTypCdList() throws BaseException {
        return this.sysDictionaryApiService.getKvList(CapPayInfoConstant.CODE_FUND_TYP_CD, CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd());
    }

    /**
     * 付款方式
     *
     * @return
     * @throws BaseException
     */
    @Override
    public List<KeyValueVO> getPayWayCdList() throws BaseException {
        return this.sysDictionaryApiService.getKvList(CapPayInfoConstant.CODE_PAY_WAYP_CD, CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd());
    }

    /**
     * 银行账号类型
     *
     * @return
     * @throws BaseException
     */
    public List<KeyValueVO> getBkAccTypCdList() throws BaseException {
        return this.sysDictionaryApiService.getKvList(CapitalConstant.CODE_SPL_BK_ACC_TYP_CD, CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd());
    }

    /**
     * 查询付款信息中租赁物数量、历史付款次数、上传资料数量
     *
     * @param vo
     * @return
     */
    public CapPayInfoVO getPayInfoCount(CapPayInfoVO vo) throws BaseException {
        if (StringUtils.isNotEmpty(vo.getPaySchId())) {
            //查询租赁物的数量
            PrjPrdDtlQueryCondition prjPrdDtlQueryCondition = new PrjPrdDtlQueryCondition();
            prjPrdDtlQueryCondition.setPaySchId(vo.getPaySchId());
            List<PrjPrdDtlVO> prjPrdDtlVOList = this.prjPrdDtlService.selectList(prjPrdDtlQueryCondition);
            int prdCount = 0;
            for (PrjPrdDtlVO prdVO : prjPrdDtlVOList) {
                prdCount += prdVO.getPrdQty();
            }
            vo.setPrdCount(prdCount);

            //查询历史付款次数
            CapPayInfoQueryCondition cpqc = new CapPayInfoQueryCondition();
            cpqc.setPaySchId(vo.getPaySchId());//支付表ID
            cpqc.setExcludeId(vo.getId());//排除
            cpqc.setPayStsCd(CapPayInfoConstant.CODE_PAY_STS_CD_FIN);//已付款
            List<CapPayInfoDTO> list = this.capPayInfoApiService.searchCapPayInfoList(cpqc);
            if (CollectionUtils.isNotEmpty(list)) {
                vo.setPayCount(list.size());
            }
        }
        //查询上传资料数量
        //String fileCount = this.getPayMateCnt(vo.getId());
        String fileCount = this.getPayMateCnt(vo.getPrjPrdDtlId()+"",vo.getBuOrgCd());
        vo.setFileCount(fileCount);
        return vo;
    }

    /**
     * 查询上传资料数量
     *
     * @param dataId 放款 项目产品ID
     * @param orgCd 组织机构
     * @return 资料数量-已上传数量
     */
    @Override
    public String getPayMateCnt(String dataId,String orgCd) throws BaseException {
        //查询放款资料配置，系统代码,组织架构代码,配置编号 ,业务主键
        SysUlDatCfgQueryCondition ulDatCfgQueryCondition = new SysUlDatCfgQueryCondition();
        ulDatCfgQueryCondition.setSysCd(CurrentThreadContext.getCurrentSysCd());//系统代码
        if(StringUtils.isNotBlank(orgCd)){
            ulDatCfgQueryCondition.setOrgCd(orgCd);//组织架构代码
        }else{
            ulDatCfgQueryCondition.setOrgCd(CapitalConstant.SYSORG);//组织架构代码
        }
        ulDatCfgQueryCondition.setDataId(dataId);//业务主键
        List<String> cfgCdList = new ArrayList<>();
        ulDatCfgQueryCondition.setCfgCdList(cfgCdList);//配置编号
        cfgCdList.add(CapitalConstant.CODE_UL_PAY_FILE_CFG_CD);//放款上传资料 配置编号
        List<SysUlDatCfgDTO> list = uploadApiService.searchSysUlDatCfgListByDataId(ulDatCfgQueryCondition);
        List<CapPayMaterialVo> voList = null;
        int totalFiles = 0;//配置全部文件数量
        int uploaded = 0;//已上传的文件数量
        if (CollectionUtils.isNotEmpty(list)) {
            for (SysUlDatCfgDTO dto : list) {
                if (CollectionUtils.isNotEmpty(dto.getSysUlDatCfgDtlDTOList())) {
                    //totalFiles += dto.getSysUlDatCfgDtlDTOList().size();
                    List<String> cfgDtlList=new ArrayList<>(dto.getSysUlDatCfgDtlDTOList().size());
                    List<String> uploadedList=new ArrayList<>(dto.getSysUlDatCfgDtlDTOList().size());
                    for (SysUlDatCfgDtlDTO dtl : dto.getSysUlDatCfgDtlDTOList()) {
                        if(!cfgDtlList.contains(dtl.getCfgDtlCd())){
                            cfgDtlList.add(dtl.getCfgDtlCd());
                            totalFiles +=1;
                        }
                        if (!uploadedList.contains(dtl.getCfgDtlCd())&&StringUtils.isNotBlank(dtl.getFilePath())) {
                            uploaded += 1;
                            uploadedList.add(dtl.getCfgDtlCd());
                        }
                    }
                }
            }
        }
        return totalFiles + "-" + uploaded;
    }

    /**
     * 初始化付款租赁物列表
     *
     * @param condition
     * @return
     */
    @Override
    public List<CapPayLeaseVO> searchLeaseList(CapPayInfoQueryCondition condition) throws BaseException {
        if (condition == null){
        	return null;
		}
        if (StringUtils.isNotEmpty(condition.getPaySchId())) {
            PrjPrdDtlQueryCondition prjPrdDtlQueryCondition = new PrjPrdDtlQueryCondition();
            prjPrdDtlQueryCondition.setPaySchId(condition.getPaySchId());
            List<PrjPrdDtlVO> dtlList = prjPrdDtlService.selectList(prjPrdDtlQueryCondition);
            if (CollectionUtils.isNotEmpty(dtlList)) {
                List<CapPayLeaseVO> voList = new ArrayList<>();
                CapPayLeaseVO lease = null;
                for (PrjPrdDtlVO vo : dtlList) {
                    lease = new CapPayLeaseVO();
                    lease.setPrjPrdDtlId(vo.getId());//项目产品明细ID
                    lease.setPrjPrdId(vo.getPrjPrdId());//项目产品ID
                    lease.setPrdId(vo.getPrdId());//产品ID
                    lease.setPrdNm(vo.getPrdNm());//产品名称
                    lease.setPrdMdl(vo.getPrdMdl());//产品型号
                    lease.setPrdQty(vo.getPrdQty());//产品数量
                    BaseLogUtils.info(logger, "searchLeaseList", "查询项目查询信息===>>>>" + vo.getPrjPrdId());
                    PrjPrdBscInfoVO pvo = prjPrdBscInfoService.selectById(vo.getPrjPrdId());
                    if (pvo != null) {
                        lease.setPrjId(pvo.getPrjId());//项目ID
                        lease.setBrCdNm(pvo.getBrCd());//品牌代码
                        lease.setPrdAmt(pvo.getPrdAmt().longValue());//产品单价
                        lease.setTtlAmt(lease.getPrdAmt() * lease.getPrdQty());//合计金额
                        List<String> codeGrpCdList = new ArrayList<String>();
                        codeGrpCdList.add(DictionaryConstant.CODE_PRD_BR_CD_TK);
                        codeGrpCdList.add(DictionaryConstant.CODE_PRD_BR_CD_CAR);
                        codeGrpCdList.add(DictionaryConstant.CODE_PRD_BR_CD_BUS);

                    }
                    voList.add(lease);
                }
                return voList;
            }
        }
        return null;
    }

    /**
     * 查询历史付款记录
     *
     * @param condition
     * @return
     * @throws BaseException
     */
    @Override
    public List<CapPayeeInfoVO> searchHisList(CapPayInfoQueryCondition condition) throws BaseException {
        List<CapPayInfoDTO> voList = this.capPayInfoApiService.searchCapPayInfoList(condition);
        if (CollectionUtils.isNotEmpty(voList)) {
            List<Long> payIds = new ArrayList<>();
            for (CapPayInfoDTO vo : voList) {
                payIds.add(vo.getId());
            }
            CapPayeeInfoQueryCondition qc = new CapPayeeInfoQueryCondition();
            qc.setPayIds(payIds);
            List<CapPayeeInfoDTO> dtoList = this.capPayeeInfoApiService.searchCapPayeeInfoList(qc);
            if (CollectionUtils.isNotEmpty(dtoList)) {
                List<CapPayeeInfoVO> payeeList = CapPayeeInfoVOTransform.toVOList(dtoList);
                //款项
                Map<String, String> fundTypCdMap = this.sysDictionaryApiService.searchGroupToMap(CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd(), CapPayInfoConstant.CODE_FUND_TYP_CD);
                for (CapPayeeInfoVO vo : payeeList) {
                    if (fundTypCdMap != null && fundTypCdMap.containsKey(vo.getFundTypCd())) {
                        vo.setFundTypCdNm(fundTypCdMap.get(vo.getFundTypCd()));
                    }
                }
                return payeeList;
            }
        }
        return null;
    }

	/**
	 * 查询上传资料记录
	 *
	 * @param condition
	 * @return
	 * @throws BaseException
	 */
	@Override
	public List<CapPayMaterialVo> searchMateList(CapPayInfoQueryCondition condition) throws BaseException {
		//查询放款资料配置，系统代码,组织架构代码,配置编号 ,业务主键
		SysUlDatCfgQueryCondition ulDatCfgQueryCondition = new SysUlDatCfgQueryCondition();

		CapPayInfoDTO payInfoDTO = null;
		if (StringUtils.isNotEmpty(condition.getId())) {
			payInfoDTO = this.capPayInfoApiService.selectCapPayInfoById(condition.getId());
			if(null != payInfoDTO){
				ulDatCfgQueryCondition.setOrgCd(payInfoDTO.getCstMgrOrgCd());//组织架构代码
			}
		}
		if(StringUtils.isBlank(ulDatCfgQueryCondition.getOrgCd())){
			ulDatCfgQueryCondition.setOrgCd(CapitalConstant.SYSORG);//组织架构代码
		}
		ulDatCfgQueryCondition.setSysCd(CurrentThreadContext.getCurrentSysCd());//系统代码
		List<String> cfgCdList = new ArrayList<>();
		ulDatCfgQueryCondition.setCfgCdList(cfgCdList);//配置编号
		if(StringUtils.isBlank(condition.getMateCfgCd())){
			//放款上传资料 配置编号默认 PRJ015  车抵贷业务:PRJ023
			condition.setMateCfgCd(CapitalConstant.CODE_UL_PAY_FILE_CFG_CD);
			if(StringUtils.isNotBlank(condition.getPrjTypCd())){
				if(PrjBscInfoConstant.PRJ_TYP_CD_CDDYW.equals(condition.getPrjTypCd())){
					condition.setMateCfgCd(PrjFileInfoConstant.CDDYW_PRD_FILE_CFG_CD);//配置编号
				}
			}else{
				if(StringUtils.isNotEmpty(condition.getPrjId())){
					PrjBscInfoVO prjBscInfoVO = this.prjBscInfoService.selectById(condition.getPrjId());
					//项目资料配置代码   车抵贷业务：PRJ022  其他：PRJ016
					if(null!=prjBscInfoVO && StringUtils.isNotBlank(prjBscInfoVO.getPrjTypCd()) && PrjBscInfoConstant.PRJ_TYP_CD_CDDYW.equals(prjBscInfoVO.getPrjTypCd())){
						condition.setMateCfgCd(PrjFileInfoConstant.CDDYW_PRD_FILE_CFG_CD);//配置编号
					}
				}
			}
		}
		cfgCdList.add(condition.getMateCfgCd());
		if(CapitalConstant.CODE_UL_PAY_FILE_CFG_CD.equals(condition.getMateCfgCd())
				||PrjFileInfoConstant.CDDYW_PRD_FILE_CFG_CD.equals(condition.getMateCfgCd())){
			//业务主键 产品明细ID 2017-03-26
			ulDatCfgQueryCondition.setDataId(String.valueOf(condition.getPrjPrdDtlId()));
		}else{
			ulDatCfgQueryCondition.setDataId(String.valueOf(condition.getPrjId()));
		}

		List<SysUlDatCfgDTO> list = uploadApiService.searchSysUlDatCfgListByDataId(ulDatCfgQueryCondition);
		List<CapPayMaterialVo> voList = null;
		if (CollectionUtils.isNotEmpty(list)) {
			Map<String, String> audStsCdMap = this.sysDictionaryApiService.searchGroupToMap(CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd(), CapitalConstant.CODE_MATE_AUD_STS_CD);
			voList = new ArrayList<>();
			CapPayMaterialVo vo;
			//设置路径
			String picServicePath = PropertiesCacheUtils.getProperty(UploadConstant.UPLOAD_SERVER_PATH);
			for (SysUlDatCfgDTO dto : list) {
				for (SysUlDatCfgDtlDTO dtlDTO : dto.getSysUlDatCfgDtlDTOList()) {
					vo = new CapPayMaterialVo();
					vo.setId(condition.getId());
					vo.setCfgDtlCd(dtlDTO.getCfgDtlCd());//配置子编号
					vo.setDatNm(dtlDTO.getDatNm());//配置名称
					vo.setCfgCd(dtlDTO.getCfgCd());//配置编号
					vo.setCfgNm(dto.getCfgNm());//配置子名称
					vo.setFileId(dtlDTO.getRecId());//附件ID
					//如果有HTTP开头说明是可以访问路径,无需干涉
					if(StringUtils.isNotBlank(dtlDTO.getFilePath())&&!dtlDTO.getFilePath().startsWith("http") && StringUtils.isNotBlank(picServicePath)){
						vo.setFilePath(picServicePath+dtlDTO.getFilePath());
					}else{
						vo.setFilePath(dtlDTO.getFilePath());//附件路径
					}
					vo.setFileNm(dtlDTO.getRecFileNm());//上传名称
					vo.setCrtTm(dtlDTO.getRecCrtTm());//上传时间
					vo.setOrgCd(dtlDTO.getOrgCd());//机构代码
					vo.setSysCd(dtlDTO.getSysCd());//系统代码
					//是否必传
					vo.setIsMust(dtlDTO.getIsMust());
					if (StringUtils.isNotBlank(dtlDTO.getRecAudStsCd())) {
						vo.setAudStsCd(dtlDTO.getRecAudStsCd());//验证状态
					} else {
						vo.setAudStsCd("0");//验证状态
					}

					if (audStsCdMap != null && audStsCdMap.containsKey(vo.getAudStsCd())) {
						vo.setAudStsCdNm(audStsCdMap.get(vo.getAudStsCd()));
					}
					voList.add(vo);
				}
			}
		}
		return voList;
	}

	/**
	 * 查询上传资料记录
	 *
	 * @param condition
	 * @return
	 * @throws BaseException
	 */
	@Override
	public List<PrjFileInfoVO> searchMateFileList(CapPayInfoQueryCondition condition,FileCfgConditonQC fileQc) throws BaseException {
		CapPayInfoDTO payInfoDTO = null;
		if (StringUtils.isNotEmpty(condition.getId())) {
			payInfoDTO = this.capPayInfoApiService.selectCapPayInfoById(condition.getId());
			if(null != payInfoDTO){
				fileQc.setPrjPrdDtlId(payInfoDTO.getPrjPrdDtlId());
				fileQc.setPrjPrdId(payInfoDTO.getPrjPrdId());
				fileQc.setPrjID(payInfoDTO.getPrjId());
			}
		}

        if(StringUtils.isBlank(condition.getMateCfgCd())){
            //放款上传资料 配置编号默认 PRJ015  车抵贷业务:PRJ023
            condition.setMateCfgCd(CapitalConstant.CODE_UL_PAY_FILE_CFG_CD);
            if(StringUtils.isNotBlank(condition.getPrjTypCd())){
                if(PrjBscInfoConstant.PRJ_TYP_CD_CDDYW.equals(condition.getPrjTypCd())){
                    condition.setMateCfgCd(PrjFileInfoConstant.CDDYW_PRD_FILE_CFG_CD);//配置编号
                }
            }else{
                if(StringUtils.isNotEmpty(condition.getPrjId())){
                    PrjBscInfoVO prjBscInfoVO = this.prjBscInfoService.selectById(condition.getPrjId());
                    //项目资料配置代码   车抵贷业务：PRJ022  其他：PRJ016
                    if(null!=prjBscInfoVO && StringUtils.isNotBlank(prjBscInfoVO.getPrjTypCd()) && PrjBscInfoConstant.PRJ_TYP_CD_CDDYW.equals(prjBscInfoVO.getPrjTypCd())){
                        condition.setMateCfgCd(PrjFileInfoConstant.CDDYW_PRD_FILE_CFG_CD);//配置编号
                    }
                }
            }
        }

		List<String> dataList=new ArrayList<>();
		if(CapitalConstant.CODE_UL_PAY_FILE_CFG_CD.equals(condition.getMateCfgCd())
				||PrjFileInfoConstant.CDDYW_PRD_FILE_CFG_CD.equals(condition.getMateCfgCd())){
			//业务主键 产品明细ID 2017-03-26
			dataList.add(String.valueOf(condition.getPrjPrdDtlId()));
		}else{
			dataList.add(String.valueOf(condition.getPrjId()));
		}
		fileQc.setIdsList(dataList);
		List<PrjFileInfoVO> list=sysUlDatCfgService.searchFileCfgList(fileQc,BaseConstant.IS_YESNO_YES_STR);
		return list;
	}

    /**
     * 修改放款资料的验证状态
     *
     * @param fileId   文件ID
     * @param audStsCd 验证状态
     * @return
     * @throws BaseException
     */
    @Override
    public boolean modifyMateStsCd(Long fileId, String audStsCd) throws BaseException {
        return this.uploadApiService.modifySysUlFilesRecAudStsCdById(fileId, audStsCd);
    }

    /**
     * 删除放款资料
     *
     * @param fileId 文件ID
     * @return
     * @throws BaseException
     */
    @Override
    public boolean removeMate(Long fileId) throws BaseException {
        List<Long> idList = new ArrayList<>(1);
        idList.add(fileId);
        return this.uploadApiService.removeSysUlFilesRecByIds(idList);
    }

    /**
     * 导出付款列表
     *
     * @param condition
     * @return
     * @throws BaseException
     */
    @Override
    public DataResultVO exportPayList(CapPayInfoExportCondition condition) throws BaseException {
        if(null==condition){
            condition=new CapPayInfoExportCondition();
        }
        condition.setSysCd(CurrentThreadContext.getCurrentSysCd());
        condition.setOrgCd(CurrentThreadContext.getCurrentOrgCd());
        condition.setUsrId(CurrentThreadContext.getCurrentUserId());
        DataResultDTO rst=this.capFundExportApiService.exportPayList(condition);
        if(null!=rst){
            return new DataResultVO(BaseConstant.IS_YESNO_YES,"导出完成",rst.getData());
        }else{
            return new DataResultVO(BaseConstant.IS_YESNO_NO,"导出失败");
        }
    }

    /**
     * 添加数据字典名称
     *
     * @param voList
     */
    public void setDictData(List<CapPayInfoVO> voList) {
        if (CollectionUtils.isEmpty(voList)) {
        	return;
		}
        //放款状态
        Map<String, String> payStsCdMap = this.sysDictionaryApiService.searchGroupToMap(CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd(), CapPayInfoConstant.CODE_PAY_STS_CD);
        //项目类型
        Map<String, String> prjTypCdMap = this.sysDictionaryApiService.searchGroupToMapAll(CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd(), DictionaryConstant.CODE_PRJ_TYPE_CD);
        //首期款代收
        Map<String, String> fstColCdMap = this.sysDictionaryApiService.searchGroupToMap(CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd(), CapPayInfoConstant.CODE_FST_COL_CD);
        //付款类型
        Map<String, String> payTypCdMap = this.sysDictionaryApiService.searchGroupToMap(CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd(), CapPayInfoConstant.CODE_PAY_TYP_CD);
        //申请来源
        Map<String, String> applyResCdMap = this.sysDictionaryApiService.searchGroupToMap(CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd(), CapPayInfoConstant.CODE_APPLY_RES_CD);
		//所属区域
		Map<String, String> cstMgrRgnCdMap = this.sysDictionaryApiService.searchGroupToMap(CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd(), DictionaryConstant.CODE_REGION_CD);
        //事业部组织架构
        //List<SysOrgDTO> list = this.sysOrgApiService.searchListByOrgTypCd(CurrentThreadContext.getCurrentSysCd());
        List<SysOrgDTO> list = this.sysOrgApiService.searchSysOrgListBy(CurrentThreadContext.getCurrentSysCd());

        Map<String, SysOrgDTO> buOrgCdMap = new HashMap<>();
        if (CollectionUtils.isNotEmpty(list)) {
            for (SysOrgDTO sysOrgDTO : list) {
                buOrgCdMap.put(sysOrgDTO.getOrgCd(), sysOrgDTO);
            }
        }
        SysOrgDTO sysOrgDTO = null;
        String orgCd = null;
        for (CapPayInfoVO vo : voList) {

            if(StringUtils.isNotBlank(vo.getRgnCityCd())){
                SysRegionDTO regionByRgnCd = sysRegionApiService.getRegionByRgnCd(vo.getRgnCityCd(), CurrentThreadContext.getCurrentSysCd());
                vo.setRgnCityCd(regionByRgnCd.getRgnNm());
            }

            if (payStsCdMap != null && payStsCdMap.containsKey(vo.getPayStsCd())) {
                vo.setPayStsCdNm(payStsCdMap.get(vo.getPayStsCd()));
            }
            if (prjTypCdMap != null && prjTypCdMap.containsKey(vo.getPrjTypCd())) {
                vo.setPrjTypCdNm(prjTypCdMap.get(vo.getPrjTypCd()));
            }
            if (buOrgCdMap.containsKey(vo.getBuOrgCd())) {
                vo.setBuOrgCdNm(buOrgCdMap.get(vo.getBuOrgCd()).getOrgNm());
            }
            if (buOrgCdMap.containsKey(vo.getCstMgrOrgCd())) {
                sysOrgDTO = buOrgCdMap.get(vo.getCstMgrOrgCd());
                vo.setCstMgrOrgCdNm(sysOrgDTO.getOrgNm());
                orgCd = sysOrgDTO.getOrgCd();
                while(orgCd.length()>8){
                    if("4".equals(sysOrgDTO.getOrgTypCd())){//分公司
                        vo.setCyOrgCdNm(sysOrgDTO.getOrgNm());
                    }else if("3".equals(sysOrgDTO.getOrgTypCd())){
                        vo.setPrOrgCdNm(sysOrgDTO.getOrgNm());
                        break;
                    }
                    orgCd = orgCd.substring(0,orgCd.length()-4);
                    if(buOrgCdMap.containsKey(orgCd)){
                        sysOrgDTO = buOrgCdMap.get(orgCd);
                    }else{
                        break;
                    }
                }
            }
            if (fstColCdMap != null && fstColCdMap.containsKey(String.valueOf(vo.getIsFstCol()))) {
                vo.setIsFstColNm(fstColCdMap.get(String.valueOf(vo.getIsFstCol())));
            }
            if (payTypCdMap != null && payTypCdMap.containsKey(vo.getPayTypCd())) {
                vo.setPayTypCdNm(payTypCdMap.get(vo.getPayTypCd()));
            }
            if(applyResCdMap!=null && applyResCdMap.containsKey(vo.getApplyResCd())){
            	vo.setApplyResCdNm(applyResCdMap.get(vo.getApplyResCd()));
            }
			if(cstMgrRgnCdMap!=null && cstMgrRgnCdMap.containsKey(vo.getCstMgrRgnCd())){
				vo.setCstMgrRgnCdNm(cstMgrRgnCdMap.get(vo.getCstMgrRgnCd()));
			}
        }
    }

/*	@Override
    public DataResultDTO addFlowStart(FlowStartParamsDTO flowStartParamsDTO) throws BaseException{
		if(StringUtils.isEmpty(flowStartParamsDTO.getBusinessKey())){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "业务数据主键必须要存在!");
		}
		flowStartParamsDTO.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
		flowStartParamsDTO.setOrgCd(CurrentThreadContext.getCurrentOrgCd());
		flowStartParamsDTO.setSysCd(CurrentThreadContext.getCurrentSysCd());
		flowStartParamsDTO.setInitiator(String.valueOf(CurrentThreadContext.getCurrentUserId()));
		flowStartParamsDTO.setInitiatorNm(CurrentThreadContext.getCurrentUserName());
		flowStartParamsDTO.setProcPriority(FlowConstant.FLOW_PRIORITY_EMERGENCY);//优先级,可以在界面定义
		flowStartParamsDTO.setBusinessType(FlowConstant.FLOW_BUSINESS_TYP_CAP_PAY_INFO);//TODO 确认用不用
		flowStartParamsDTO.setModelTyp(FlowConstant.FLOW_MODEL_TYP_CAP_PAY_1);//需要和流程配置中的模块类型匹配
		flowStartParamsDTO.setSearchDesc(CurrentThreadContext.getCurrentOrgDispNm()+"、承租人、项目名称、查询大字段名称");
		return this.capPayInfoApiService.addFlowStart(flowStartParamsDTO,CurrentThreadContext.getCurrentSysCd(),CurrentThreadContext.getCurrentOrgCd());
	}*/

    @Override
    public List<KeyValueVO> searchYesOrNOList() throws BaseException {
        return this.getKvList(DictionaryConstant.CODE_SYS_YES_NO_CD);
    }
    
    @Override
	public List<KeyValueVO> searchOrgBizOpnCdList() throws BaseException {
    	return this.getKvList(PrjBscInfoConstant.PRJ_ORG_BIZ_OPN_CD);
	}

	@Override
   	public List<KeyValueVO> searchIsGrpList() throws BaseException {
       	return this.getKvList(DictionaryConstant.CODE_IS_GRP_CD);
   	}

    /**
     * 根据字典中代码组值获取组员集合
     *
     * @param grpCd 代码组值
     * @return 集合
     */
    private List<KeyValueVO> getKvList(String grpCd) {
        List<KeyValueVO> kvList = new ArrayList<>();
        try {
            List<SysDictionaryDTO> sysDictionaryDTOList = this.sysDictionaryApiService.searchGroup(CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd(), grpCd);
            if (CollectionUtils.isNotEmpty(sysDictionaryDTOList)) {
                for (SysDictionaryDTO sysDictionaryDTO : sysDictionaryDTOList) {
                    KeyValueVO keyValueVO = new KeyValueVO();
                    keyValueVO.setKey(sysDictionaryDTO.getCode());
                    keyValueVO.setValue(sysDictionaryDTO.getCodeNm());
                    kvList.add(keyValueVO);
                }
            }
        } catch (BaseException e) {
            BaseLogUtils.info(logger, "getKvList", "获取字典项组" + grpCd + "失败.ERROR:" + e.getMessage(), CurrentThreadContext.getCurrentUserName());
        } catch (Exception e) {
            BaseLogUtils.error(logger, "getKvList", "获取字典项组" + grpCd + "失败,系统错误.ERROR:" + e.getMessage(), CurrentThreadContext.getCurrentUserName());
        }
        return kvList;
    }

    //****************************************private********************************************

    /**
     * 根据放款类型获取流程业务分类
     *
     * @param payTypCd
     * @param sysCd
     * @param orgCd
     * @return
     * @throws BaseException
     */
    private String getFlowModelTyp(String payTypCd, String sysCd, String orgCd) throws BaseException {
        if (StringUtils.isEmpty(payTypCd)) {
            throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "放款类型不能为空.");
        }
        SysCdMapDQueryCondition cdMapQC = new SysCdMapDQueryCondition();
        cdMapQC.setSysCd(sysCd);
        cdMapQC.setOrgCd(orgCd);
        cdMapQC.setmTypCd("M0007");
        cdMapQC.setsCode(payTypCd);
        List<SysCdMapDDTO> sysCdMapDList = this.sysCdMapApiService.searchSysCdMapDWithTargetList(cdMapQC);
        if (CollectionUtils.isNotEmpty(sysCdMapDList)) {
            SysCdMapDDTO sysCdMapDDTO = sysCdMapDList.get(0);
            return sysCdMapDDTO.getTCode();
        }
        return null;
    }

    /**
     * 获取发起流程对象
     *
     * @param businessType:业务类型(FlowConstant.FLOW_BUSINESS_TYP_CAP_PAY_INFO)
     * @param modelTyp:流程业务分类
     * @return
     * @throws BaseException
     */
    private FlowStartParamsDTO getFlowStartParams(String businessType, String modelTyp) throws BaseException {
        if (StringUtils.isEmpty(modelTyp)) {
            throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "流程业务分类不能为空");
        }
        FlowStartParamsDTO flowStartParamsDTO = new FlowStartParamsDTO();
        //流程定义KEY和流程定义ID不定义  流程发起的时候会根据模块类型查找唯一流程去发起
        //flowStartParamsDTO.setProcDefKey("");
        //flowStartParamsDTO.setProcDefId("");
        flowStartParamsDTO.setAudStsCd(FlowConstant.FLOW_CHECK_STATE_IN);
        flowStartParamsDTO.setWordsInTheTable(CapPayInfoConstant.CAP_FLOW_S_H_CAP);
        flowStartParamsDTO.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
        flowStartParamsDTO.setOrgCd(CurrentThreadContext.getCurrentOrgCd());
        flowStartParamsDTO.setSysCd(CurrentThreadContext.getCurrentSysCd());
        flowStartParamsDTO.setBuOrgCd(CurrentThreadContext.getCurrentBuOrgCd());
        flowStartParamsDTO.setInitiator(String.valueOf(CurrentThreadContext.getCurrentUserId()));
        flowStartParamsDTO.setInitiatorNm(CurrentThreadContext.getCurrentUserName());
        flowStartParamsDTO.setProcPriority(FlowConstant.FLOW_PRIORITY_EMERGENCY);//优先级,可以在界面定义
        flowStartParamsDTO.setBusinessType(businessType);//TODO 确认用不用
        flowStartParamsDTO.setModelTyp(modelTyp);//需要和流程配置中的模块类型匹配
        //flowStartParamsDTO.setSearchDesc(CurrentThreadContext.getCurrentOrgDispNm()+"、承租人、项目名称、查询大字段名称");
        return flowStartParamsDTO;
    }
    
    /**
     * 获取放款流程发起参数
     * @param capPayFlowCfgParmVO
     * @return
     * @throws BaseException
     */
    private FlowStartParamsDTO getFlowStartObj(CapPayFlowCfgParmVO capPayFlowCfgParmVO) throws BaseException {
    	if(null==capPayFlowCfgParmVO || StringUtils.isEmpty(capPayFlowCfgParmVO.getPayTypCd())){
    		throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "付款类型不能为空.");
    	}
    	if(StringUtils.isEmpty(capPayFlowCfgParmVO.getPayTypCd())){
    		throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "客户经理组织架构不能为空.");
    	}
    	String payTypCd = capPayFlowCfgParmVO.getPayTypCd();//付款类型 
    	Integer isNewPrd = capPayFlowCfgParmVO.getIsNewPrd();//是否新车
    	String cstMgrOrgCd = capPayFlowCfgParmVO.getCstMgrOrgCd();//客户经理组织架构 
    	String prjTypCd = capPayFlowCfgParmVO.getPrjTypCd();//项目类型
    	
    	String modelTyp = this.getFlowModelTyp(payTypCd, CurrentThreadContext.getCurrentSysCd(), cstMgrOrgCd);
    	if (StringUtils.isEmpty(modelTyp)) {
    		throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "流程业务分类不能为空");
    	}
    	
    	String procDefKey = capPayFlowCfgParmVO.getProcDefKey();//流程定义KEY
    	String procDefId = "";//流程定义ID
    	String procNo = "";//流程编号
    	
    	if(StringUtils.isEmpty(procDefKey)){
    		//根据参数查找配置
    		//0.项目类型|放款类型
    		if(StringUtils.isNotEmpty(prjTypCd)){
    			StringBuffer sCode = new StringBuffer();
    			sCode.append(prjTypCd);
    			sCode.append("|");
    			sCode.append(payTypCd);
    			List<SysCdMapDDTO> sysCdMapDDTOList = this.getProcDefKey(cstMgrOrgCd, PropertiesCacheUtils.getProperty(SysCdMapConstant.M_TYP_CD_PAY_PRJ_TYP_CD), sCode.toString());
    			if(CollectionUtils.isNotEmpty(sysCdMapDDTOList) && sysCdMapDDTOList.size()==1){
    				SysCdMapDDTO sysCdMapDDTO = sysCdMapDDTOList.get(0);
    				procDefKey = sysCdMapDDTO.getTCode();
    			}
    		}
    		if(StringUtils.isNotEmpty(prjTypCd) && prjTypCd.equals(PrjBscInfoConstant.PRJ_TYP_CD_GHKD) && StringUtils.isEmpty(procDefKey)){
    			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_604, "未找到要发起的流程.");
    		}
    		if(StringUtils.isNotEmpty(prjTypCd) && prjTypCd.equals(PrjBscInfoConstant.CODE_PRJ_TYP_CD_BILLING_CD) && StringUtils.isEmpty(procDefKey)){
    			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_604, "未找到要发起的流程.");
    		}
    		if(StringUtils.isNotEmpty(prjTypCd) && prjTypCd.equals(PrjBscInfoConstant.PRJ_TYP_CD_ESC) && StringUtils.isEmpty(procDefKey)){
    			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_604, "未找到要发起的流程.");
    		}
    		if(StringUtils.isNotEmpty(prjTypCd) && prjTypCd.equals(PrjBscInfoConstant.PRJ_TYP_CD_CDDYWUL) && StringUtils.isEmpty(procDefKey)){
    			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_604, "未找到要发起的流程.");
    		}
    		//1.是否新车|放款类型
    		if(StringUtils.isEmpty(procDefKey)){
    			if(StringUtils.isNotEmpty(isNewPrd)){
    				StringBuffer sCode = new StringBuffer();
    				sCode.append(isNewPrd);
    				sCode.append("|");
    				sCode.append(payTypCd);
    				List<SysCdMapDDTO> sysCdMapDDTOList = this.getProcDefKey(cstMgrOrgCd, PropertiesCacheUtils.getProperty(SysCdMapConstant.M_TYP_CD_PAY_TYP_CD), sCode.toString());
    				if(CollectionUtils.isNotEmpty(sysCdMapDDTOList) && sysCdMapDDTOList.size()==1){
    					SysCdMapDDTO sysCdMapDDTO = sysCdMapDDTOList.get(0);
    					procDefKey = sysCdMapDDTO.getTCode();//配置流程定义KEY
    					
    				}
    			}
    		}
    	}
		if(StringUtils.isNotEmpty(procDefKey)){
			//查询流程版本
			SysFlowManageVQueryCondition flowManaQC = new SysFlowManageVQueryCondition();
			flowManaQC.setSysCd(CurrentThreadContext.getCurrentSysCd());
			flowManaQC.setIsDel(BaseConstant.IS_YESNO_NO);
			flowManaQC.setIsValid(BaseConstant.IS_YESNO_YES);
			flowManaQC.setModelTyp(modelTyp);
			flowManaQC.setOrgCd(cstMgrOrgCd);
			flowManaQC.setProcDefKey(procDefKey);
			List<SysFlowManageVDTO> flowManageVListForStart = this.flowApiService.searchFlowManageVListForStart(flowManaQC);
			if(CollectionUtils.isNotEmpty(flowManageVListForStart) && flowManageVListForStart.size()==1){
				SysFlowManageVDTO sysFlowManageVDTO = flowManageVListForStart.get(0);
				procDefId  = sysFlowManageVDTO.getProcDefId();
				procNo = sysFlowManageVDTO.getProcNo();
			}
		}
    	
    	FlowStartParamsDTO flowStartParamsDTO = new FlowStartParamsDTO();
    	flowStartParamsDTO.setProcDefKey(procDefKey);
    	flowStartParamsDTO.setProcDefId(procDefId);
    	flowStartParamsDTO.setProcNo(procNo);
    	flowStartParamsDTO.setAudStsCd(FlowConstant.FLOW_CHECK_STATE_IN);
    	flowStartParamsDTO.setWordsInTheTable(CapPayInfoConstant.CAP_FLOW_S_H_CAP);
    	flowStartParamsDTO.setCrtUsrId(capPayFlowCfgParmVO.getCstMgrId());
    	flowStartParamsDTO.setOrgCd(cstMgrOrgCd);
    	flowStartParamsDTO.setSysCd(CurrentThreadContext.getCurrentSysCd());
    	flowStartParamsDTO.setBuOrgCd(capPayFlowCfgParmVO.getBuOrgCd());
    	flowStartParamsDTO.setInitiator(String.valueOf(capPayFlowCfgParmVO.getCstMgrId()));
    	flowStartParamsDTO.setInitiatorNm(capPayFlowCfgParmVO.getCstMgrNm());
    	flowStartParamsDTO.setProcPriority(FlowConstant.FLOW_PRIORITY_EMERGENCY);//优先级,可以在界面定义
    	flowStartParamsDTO.setBusinessType(FlowConstant.FLOW_BUSINESS_TYP_CAP_PAY_INFO);//TODO 确认用不用
    	flowStartParamsDTO.setModelTyp(modelTyp);//需要和流程配置中的模块类型匹配
    	//flowStartParamsDTO.setSearchDesc(CurrentThreadContext.getCurrentOrgDispNm()+"、承租人、项目名称、查询大字段名称");
    	return flowStartParamsDTO;
    }
    
    private List<SysCdMapDDTO> getProcDefKey(String orgCd,String mTypCd, String sCode)throws BaseException{
		SysCdMapDQueryCondition qc = new SysCdMapDQueryCondition();
		qc.setSysCd(CurrentThreadContext.getCurrentSysCd());
		qc.setOrgCd(orgCd);
		qc.setmTypCd(mTypCd);
		List<String> getsCodeList = new ArrayList<>();
		getsCodeList.add(sCode);
		qc.setsCodeList(getsCodeList);
		BaseLogUtils.info(logger, "addFlowStart", "===调ISysCdMapApiService查询映射的流程KEY开始===condition:"+JSON.toJSONString(qc));
		List<SysCdMapDDTO> mapDList = this.sysCdMapApiService.searchSysCdMapDWithTargetList(qc);
		BaseLogUtils.info(logger, "addFlowStart", "===调ISysCdMapApiService查询映射的流程KEY结束===mapDList:"+JSON.toJSONString(mapDList));
		return mapDList;
	}

	@Override
	public boolean modifyCapSysFlowSH(Long capPayId, String processInstanceId) throws BaseException {
		if(StringUtils.isEmpty(capPayId) || StringUtils.isEmpty(processInstanceId)){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, BaseExceptionConstant.BASE_EXCEPTION_CODE_600_NAME);
		}
		CapPayInfoDTO capPayInfoDTO = new CapPayInfoDTO();
		capPayInfoDTO.setId(Long.valueOf(capPayId));
		capPayInfoDTO.setPayStsCd(CapPayInfoConstant.CODE_PAY_STS_CD_N_START);//未申请
		capPayInfoDTO.setPayTypCd(CapPayInfoConstant.CODE_PAY_TYP_CD_3);//特殊放款
		
		SysFlowSHDTO sysFlowSHDTO = new SysFlowSHDTO();
		sysFlowSHDTO.setDataId(capPayId);
		sysFlowSHDTO.setPInstId(processInstanceId);
		sysFlowSHDTO.setSysCd(CurrentThreadContext.getCurrentSysCd());
		sysFlowSHDTO.setStatus(BaseConstant.IS_YESNO_NO);
		sysFlowSHDTO.setWordsInTheTable(CapPayInfoConstant.CAP_FLOW_S_H_CAP);
		
		BaseLogUtils.info(logger, "modifyCapSysFlowSH", "===取消付款Start===capPayInfoDTO:"+JSON.toJSONString(capPayInfoDTO)+",sysFlowSHDTO:"+JSON.toJSONString(sysFlowSHDTO));
		boolean modifyCapSysFlowSH = this.capPayInfoApiService.modifyCapSysFlowSH(capPayInfoDTO, sysFlowSHDTO);
		BaseLogUtils.info(logger, "modifyCapSysFlowSH", "===取消付款Start===modifyCapSysFlowSH:"+modifyCapSysFlowSH);
		
		return modifyCapSysFlowSH;
	}

	@Override
	public boolean addCapPayInfoAndFlowSH(FlowCompleteParamsDTO flowCompleteParamsDTO) throws BaseException {
		return this.capPayInfoApiService.addCapPayInfoAndFlowSH(flowCompleteParamsDTO);
	}

	/**
     * 校验附件《所有权转让协议首页》是否上传，若未上传不可通过该流程
     */
    @Override
    public DataResultVO checkTransfeOfTitle(Long prjId, Long prjPrdDtlId) throws BaseException {

        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
        try {

            if (isCheckUploadFileFlag("3000")) {
                // 所有权转让协议（首页）PRJ016-91 | 车抵贷 PRJ022-91
                String cfgCd = PrjBscInfoConstant.CODE_PRJ_FILE_CD;// PRJ016
                List<String> cfgDtlCdList = new ArrayList<String>();
                cfgDtlCdList.add("91");

                if (prjId != null) {
                    // 是否车抵贷业务
                    PrjBscInfoVO prjBscInfoVO = this.prjBscInfoService.selectById(prjId);// 项目信息
                    if (null != prjBscInfoVO
                            && PrjBscInfoConstant.PRJ_TYP_CD_CDDYW.equals(prjBscInfoVO.getPrjTypCd())) {
                        cfgCd = PrjFileInfoConstant.CDDYW_PRJ_FILE_CFG_CD;// PRJ022
                    }
                    if (prjPrdDtlId != null) {
                        PrjPrdDtlVO prjPrdDtlVO = this.prjPrdDtlService.selectById(prjPrdDtlId);// 项目产品明细
                        if (null != prjPrdDtlVO) {
                            result = this.searchCheckPrjFileInfo(prjId,
                                    PropertiesCacheUtils.getProperty(SystemConstant.FL_SERVICE_CD),
                                    prjBscInfoVO.getCstMgrOrgCd(), cfgCd, cfgDtlCdList, "请上传《所有权转让协议（首页）》");
                        }
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
//          result.setCode(String.valueOf(BaseConstant.IS_YESNO_NO));
            result.setInfo("系统异常.");
            BaseLogUtils.info(logger, "",
                    "checkTransfeOfTitle,prjId:" + prjId + "prjPrdDtlId:" + prjPrdDtlId + "," + e.getMessage());
        }

        return result;
    }

    /**
     * 1000 类城配流程:《所有权转让协议首页》是否上传
     * 2000 非城配流程:《所有权转让协议首页》是否上传
     * 3000 《登记证-车辆信息页》、《登记证-抵押我司页》是否上传
     *
     * @return
     */
    private boolean isCheckUploadFileFlag(String code) {
        boolean flag = false;
        if (StringUtils.isNotBlank(code)) {
            List<SysDictionaryDTO> sysDictionaryDTOList = this.sysDictionaryApiService.searchGroup(
                    PropertiesCacheUtils.getProperty(SystemConstant.FL_SERVICE_CD),
                    PropertiesCacheUtils.getProperty(SystemConstant.FL_ORG_CD), "PRJ0145");
            if (sysDictionaryDTOList != null && sysDictionaryDTOList.size() > 0) {
                for (SysDictionaryDTO sysDictionaryDTO : sysDictionaryDTOList) {
                    if (code.equals(sysDictionaryDTO.getCode())) {
                        flag = true;
                        break;
                    }
                }
            }
        }

        return flag;
    }
    public DataResultVO searchCheckPrjFileInfo(Long dataId, String sysCd, String orgCd, String cfgCd,
            List<String> cfgDtlCdList,String info) {
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);

        try {
            if (null == dataId || StringUtils.isEmpty(sysCd) || StringUtils.isEmpty(orgCd)
                    || CollectionUtils.isEmpty(cfgDtlCdList)) {
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo("请求参数不完整.");
                BaseLogUtils.info(logger, "searchCheckPrjFileInfo", "=校验资料请求参数不完整=dataId:" + dataId + ",sysCd:" + sysCd
                        + ",orgCd:" + orgCd + ",cfgCd:" + cfgCd + ",cfgDtlCdList:" + JSON.toJSONString(cfgDtlCdList));
                return result;
            }
            SysUlDatCfgQueryCondition ulDatCfgQueryCondition = new SysUlDatCfgQueryCondition();
            ulDatCfgQueryCondition.setSysCd(sysCd);// 系统代码
            ulDatCfgQueryCondition.setOrgCd(orgCd);
            ulDatCfgQueryCondition.setDataId(String.valueOf(dataId));// 业务主键
            List<String> cfgCdList = new ArrayList<String>();
            cfgCdList.add(cfgCd);
            ulDatCfgQueryCondition.setCfgCdList(cfgCdList);
            BaseLogUtils.info(logger, "searchCheckPrjFileInfo", "=查询资料Start=dataId:" + dataId
                    + ",ulDatCfgQueryCondition:" + JSON.toJSONString(ulDatCfgQueryCondition));
            List<SysUlDatCfgDTO> sysUlDatCfgDTOList = this.uploadApiService
                    .searchSysUlDatCfgListByDataId(ulDatCfgQueryCondition);
            BaseLogUtils.info(logger, "searchCheckPrjFileInfo",
                    "=查询资料End=dataId:" + dataId + ",sysUlDatCfgDTOList:" + JSON.toJSONString(sysUlDatCfgDTOList));

            List<String> exitfgDtlCdList = new ArrayList<String>();
            for (SysUlDatCfgDTO sysUlDatCfgDTO : sysUlDatCfgDTOList) {
                if (null != sysUlDatCfgDTO && CollectionUtils.isNotEmpty(sysUlDatCfgDTO.getSysUlDatCfgDtlDTOList())) {
                    List<SysUlDatCfgDtlDTO> sysUlDatCfgDtlDTOList = sysUlDatCfgDTO.getSysUlDatCfgDtlDTOList();
                    if (CollectionUtils.isNotEmpty(sysUlDatCfgDtlDTOList)) {
                        for (SysUlDatCfgDtlDTO sysUlDatCfgDtlDTO : sysUlDatCfgDtlDTOList) {
                            if (!exitfgDtlCdList.contains(sysUlDatCfgDtlDTO.getCfgDtlCd())
                                    && StringUtils.isNotEmpty(sysUlDatCfgDtlDTO.getFilePath())) {
                                exitfgDtlCdList.add(sysUlDatCfgDtlDTO.getCfgDtlCd());
                            }
                        }
                    }
                }
            }
            if (!exitfgDtlCdList.containsAll(cfgDtlCdList)) {
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                if(StringUtils.isNotBlank(info)) {
                    result.setInfo(info);
                }else {
                    result.setInfo("校验不通过,上传资料不完整.");
                }
                result.setData(exitfgDtlCdList);
            }
        } catch (BaseException e) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo("校验失败.");
            BaseLogUtils.info(logger, "searchCheckPrjFileInfo", "=校验资料失败=dataId:" + dataId + "," + e.getMessage());
            e.printStackTrace();
        } catch (Exception e) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo("系统异常.");
            BaseLogUtils.info(logger, "searchCheckPrjFileInfo", "=校验资料异常=dataId:" + dataId + "," + e.getMessage());
            e.printStackTrace();
        }
        BaseLogUtils.info(logger, "searchCheckPrjFileInfo",
                "=校验资料返回结果=dataId:" + dataId + ",result:" + JSON.toJSONString(result));
        return result;
    }

    /**
	    * 放款流程发起成功-同步修改项目产品基础信息中的付款账号
	 * @param entity
	 * @return
	 * @throws BaseException
	 */
    @Override
    public boolean updateSplAccNoId(CapPayInfoVO entity) throws BaseException {
        if (null == entity) return false;
        return this.capPayInfoApiService.updateSplAccNoId(CapPayInfoVOTransform.toDTO(entity));
    }

	@Override
	public Pager searchCddYqCutPayListPage(Pager page) throws BaseException {
		CapPayInfoQueryCondition condition = null;
		if (null == page) {
			page = new Pager();
			page.setCondition(new CapPayInfoQueryCondition());
		}
		condition = (CapPayInfoQueryCondition) page.getCondition();
		condition.setSysCd(CurrentThreadContext.getCurrentSysCd());//当前系统代码
		condition.setOrgCd(CurrentThreadContext.getCurrentOrgCd());//当前机构代码
		condition.setUsrId(CurrentThreadContext.getCurrentUserId());//当前用户ID
		page = this.capPayInfoApiService.searchCddYqCutPayListPage(page);
		if (CollectionUtils.isNotEmpty(page.getResultList())) {
			List<CapPayInfoVO> voList = CapPayInfoVOTransform.toVOList((List<CapPayInfoDTO>) page.getResultList());
			//放款状态
			Map<String, String> payStsCdMap = this.sysDictionaryApiService.searchGroupToMap(CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd(), CapPayInfoConstant.CODE_PAY_STS_CD);
			//事业部组织架构
			List<SysOrgDTO> list = this.sysOrgApiService.searchSysOrgListBy(CurrentThreadContext.getCurrentSysCd());
			Map<String, SysOrgDTO> buOrgCdMap = new HashMap<>();
			if (CollectionUtils.isNotEmpty(list)) {
				for (SysOrgDTO sysOrgDTO : list) {
					buOrgCdMap.put(sysOrgDTO.getOrgCd(), sysOrgDTO);
				}
			}
			for (CapPayInfoVO vo : voList) {
				if (payStsCdMap != null && payStsCdMap.containsKey(vo.getPayStsCd())) {
					vo.setPayStsCdNm(payStsCdMap.get(vo.getPayStsCd()));
				}
				if (buOrgCdMap.containsKey(vo.getBuOrgCd())) {
					vo.setBuOrgCdNm(buOrgCdMap.get(vo.getBuOrgCd()).getOrgNm());
				}
			}
			page.setResultList(voList);
			BaseLogUtils.newLogger("查询车抵贷（YQ）手动扣款列表数据vo:" + JSON.toJSONString(voList)).setLogOperType(LogOperEnum.SELECT).setWarning(false).info();
		}
		return page;
	}

	@Override
	public DataResultDTO confirmCutPay(String payId, String cstId, String cutPaySchNo, String paySchId, String paySchNo) throws BaseException {
		//根据付款ID获取 供应商/承租人银行账户ID
		CapPayeeInfoQueryCondition qc = new CapPayeeInfoQueryCondition();
		qc.setPayId(Long.valueOf(payId));
		qc.setPurpCd(CapPayeeInfoConstant.CODE_PURP_CD_00000008_1);
		BaseLogUtils.newServiceLogger("===查询收款信息Start==qc:" + JSON.toJSONString(qc)).info();
		List<CapPayeeInfoVO> capPayeeInfoList = this.capPayeeInfoService.searchList(qc);
		BaseLogUtils.newServiceLogger("===查询收款信息End==capPayeeInfoList:" + JSON.toJSONString(capPayeeInfoList)).info();
		RepaymentDTO repaymentDTO = new RepaymentDTO();
		repaymentDTO.setCstId(Long.valueOf(cstId));
		repaymentDTO.setPaySchNo(cutPaySchNo);
		if (CollectionUtils.isNotEmpty(capPayeeInfoList)){
			CapPayeeInfoVO capPayeeInfoVO = capPayeeInfoList.get(0);
			repaymentDTO.setBankId(capPayeeInfoVO.getBkId());
			repaymentDTO.setPayMoney(capPayeeInfoVO.getActPayAmt());
		}
		repaymentDTO.setNewPaySchNo(paySchNo);
		BaseLogUtils.newServiceLogger("===车抵贷（疫情）扣款Start===repaymentDTO:" + JSON.toJSONString(repaymentDTO)).info();
		DataResultDTO repayment = carLoanEpidemicApiService.repayment(repaymentDTO);
		BaseLogUtils.newServiceLogger("===车抵贷（疫情）扣款Start===repayment:" + JSON.toJSONString(repayment)).info();
		return repayment;
	}

	@Override
	public Pager searchCddYqCutPayFailListPage(Pager page) throws BaseException {
		CapPayInfoQueryCondition condition = null;
		if (null == page) {
			page = new Pager();
			page.setCondition(new CapPayInfoQueryCondition());
		}
		condition = (CapPayInfoQueryCondition) page.getCondition();
		condition.setSysCd(CurrentThreadContext.getCurrentSysCd());//当前系统代码
		condition.setOrgCd(CurrentThreadContext.getCurrentOrgCd());//当前机构代码
		condition.setUsrId(CurrentThreadContext.getCurrentUserId());//当前用户ID
		try {
			page = this.capPayInfoApiService.searchCddYqCutPayFailListPage(page);
			BaseLogUtils.newWebLogger("===查询车抵贷（YQ）手动扣款（扣款失败）列表数据===page:" + JSON.toJSONString(page)).info();
			if (CollectionUtils.isNotEmpty(page.getResultList())) {
				List<CapPayInfoVO> voList = CapPayInfoVOTransform.toVOList((List<CapPayInfoDTO>) page.getResultList());
				//放款状态
				Map<String, String> payStsCdMap = this.sysDictionaryApiService.searchGroupToMap(CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd(), CapPayInfoConstant.CODE_PAY_STS_CD);
				//事业部组织架构
				List<SysOrgDTO> list = this.sysOrgApiService.searchSysOrgListBy(CurrentThreadContext.getCurrentSysCd());
				Map<String, SysOrgDTO> buOrgCdMap = new HashMap<>();
				if (CollectionUtils.isNotEmpty(list)) {
					for (SysOrgDTO sysOrgDTO : list) {
						buOrgCdMap.put(sysOrgDTO.getOrgCd(), sysOrgDTO);
					}
				}
				for (CapPayInfoVO vo : voList) {
					if (payStsCdMap != null && payStsCdMap.containsKey(vo.getPayStsCd())) {
						vo.setPayStsCdNm(payStsCdMap.get(vo.getPayStsCd()));
					}
					if (buOrgCdMap.containsKey(vo.getBuOrgCd())) {
						vo.setBuOrgCdNm(buOrgCdMap.get(vo.getBuOrgCd()).getOrgNm());
					}
				}
				page.setResultList(voList);
				BaseLogUtils.newLogger("查询车抵贷（YQ）手动扣款（扣款失败）列表数据vo:" + JSON.toJSONString(voList)).setLogOperType(LogOperEnum.SELECT).setWarning(false).info();
			}
		}catch (BaseException ex) {
			BaseLogUtils.newWebLogger("操作失败,ex:" + JSON.toJSONString(ex.getMessage())).info();
		}catch (Exception ex) {
			BaseLogUtils.newWebLogger("操作失败,ex:" + JSON.toJSONString(ex)).setThrowable(ex).error(LogExceptionEnum.COMMON_CODE_0002);
		}
		BaseLogUtils.newLogger("查询车抵贷（YQ）手动扣款（扣款失败）列表数据page:" + JSON.toJSONString(page)).info();
		return page;
	}

	@Override
	public DataResultDTO refreshCutPayStsCd(String cutPaySchNo, String paySchNo, String cstId) throws BaseException {
		BaseLogUtils.newServiceLogger("===调用车抵贷（疫情）实时查询刷新扣款状态Start，传入参数==>cutPaySchNo=" + cutPaySchNo + "&paySchNo=" + paySchNo + "&cstId=" + cstId).info();
		DataResultDTO resultDTO = carLoanEpidemicApiService.orderCurrentQuery(cutPaySchNo,paySchNo,cstId);
		BaseLogUtils.newServiceLogger("===调用车抵贷（疫情）实时查询刷新扣款状态End===resultDTO:" + JSON.toJSONString(resultDTO)).info();
		return resultDTO;
	}

	@Override
	public Object getGPSFlag(PrjBscInfoVO prjBscInfoVO) throws BaseException {
		if (null != prjBscInfoVO && null != prjBscInfoVO.getRcCstBscInfoId()) {
			BaseParamDTO baseParamDTO = new BaseParamDTO();
			baseParamDTO.setSysCd(CurrentThreadContext.getCurrentSysCd());
			baseParamDTO.setChannelCd(WebBaseConstant.CHANNEL_CD);
			baseParamDTO.setFrontCd(PropertiesCacheUtils.getProperty(WebBaseConstant.FL_SERVICE_SYS_CD));
			baseParamDTO.setServiceCd(PropertiesCacheUtils.getProperty(WebBaseConstant.FL_SERVICE_SYS_CD));
			BaseLogUtils.newLogger("查询是否安装有限GPS入参id=" + prjBscInfoVO.getRcCstBscInfoId() + "baseParamDTO=" + JSON.toJSONString(baseParamDTO)).info();
			DataResultDTO dataResultDTO = externalAcardGpsApiService.getAcardGps(prjBscInfoVO.getRcCstBscInfoId(), baseParamDTO);
			BaseLogUtils.newLogger("查询是否安装有限GPS结果prjId=" + prjBscInfoVO.getId() + "dataResultDTO=" + JSON.toJSONString(dataResultDTO)).info();
			if (null != dataResultDTO && null != dataResultDTO.getData()) {
				return dataResultDTO.getData();
			}
		}
		return 0;
	}

	@Override
	public Integer getNoPassAudCarNum(PrjBscInfoVO prjBscInfoVO) throws BaseException {
    	if (prjBscInfoVO == null || prjBscInfoVO.getId() == null) {
    		return 0;
		}
    	Long prjId = prjBscInfoVO.getId();
		int noPassAudCarNum = 0;
		PrjPrdDtlQueryCondition ppdQC = new PrjPrdDtlQueryCondition();
		ppdQC.setPrjId(prjId);
		ppdQC.setIsDel(0);
		BaseLogUtils.newLogger("信审页面查询项目产品明细开始").info();
		List<PrjPrdDtlVO> prjPrdDtlVOList = this.prjPrdDtlService.selectList(ppdQC);
		BaseLogUtils.newLogger("信审页面查询项目产品明细prjId:" + prjId + ",prjPrdDtlDTOList:" + JSON.toJSONString(prjPrdDtlVOList)).info();
		HashSet<Long> set = new HashSet<>();
		if (CollectionUtils.isNotEmpty(prjPrdDtlVOList)) {
			for (PrjPrdDtlVO prjPrdDtlVO : prjPrdDtlVOList) {
				if (StringUtils.isNotEmpty(prjPrdDtlVO.getLnkCompId())) {
					set.add(prjPrdDtlVO.getLnkCompId());
				}
			}
		}
		BaseLogUtils.newLogger("信审页面项目产品明细集合prjId:" + prjId + ",set:" + JSON.toJSONString(set)).info();
		if (CollectionUtils.isNotEmpty(set)) {
			Iterator<Long> iterator = set.iterator();
			List<Long> dtlIdList = new ArrayList<>();
			while (iterator.hasNext()) {
				PrjPrdDtlQueryCondition dtlQc = new PrjPrdDtlQueryCondition();
				dtlQc.setLnkCompId(iterator.next());
				dtlQc.setIsDel(0);
				BaseLogUtils.newLogger("信审页面查询项目产品明细开始").info();
				List<PrjPrdDtlVO> prjPrdDtlVOList1 = this.prjPrdDtlService.selectList(dtlQc);
				BaseLogUtils.newLogger("信审页面查询项目产品明细1prjId:" + prjId + ",prjPrdDtlVOList1:" + JSON.toJSONString(prjPrdDtlVOList1)).info();
				for (PrjPrdDtlVO vo : prjPrdDtlVOList1) {
					dtlIdList.add(vo.getId());
				}
			}
			if (CollectionUtils.isNotEmpty(dtlIdList)) {
				CapPayInfoQueryCondition capPayInfoQueryCondition = new CapPayInfoQueryCondition();
				capPayInfoQueryCondition.setIsDel(0);
				capPayInfoQueryCondition.setPrjPrdDtlIds(dtlIdList);
				capPayInfoQueryCondition.setPayStsCdList(Arrays.asList("3","5"));
				List<CapPayInfoVO> capPayInfoVOS = this.searchList(capPayInfoQueryCondition);
				BaseLogUtils.newLogger("信审页面查询项目产品prjId=" + prjId + ",capPayInfoVOS=" + JSON.toJSONString(capPayInfoVOS)).info();
				if (CollectionUtils.isNotEmpty(capPayInfoVOS)) {
					noPassAudCarNum = capPayInfoVOS.size();
					PrjPrdMtgQueryCondition prdMtgQueryCondition = new PrjPrdMtgQueryCondition();
					prdMtgQueryCondition.setIdList(dtlIdList);
					prdMtgQueryCondition.setGuarStsCds(Arrays.asList("2", "3", "4"));
					List<PrjPrdMtgDTO> prjPrdMtgDTOS = projectApiService.searchPrjPrdMtgList(prdMtgQueryCondition, CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd());
					BaseLogUtils.newLogger("信审页面查询抵押信息prjId:" + prjId + ",prjPrdMtgDTOS:" + JSON.toJSONString(prjPrdMtgDTOS)).info();
					if (CollectionUtils.isNotEmpty(prjPrdMtgDTOS)) {
						noPassAudCarNum = capPayInfoVOS.size() - prjPrdMtgDTOS.size();
					}
				}
            }
		}
		BaseLogUtils.newLogger("信审页面查询抵押信息prjId:" + prjId+ ",noPassAudCarNum:" + noPassAudCarNum).info();
    	return noPassAudCarNum;
	}

	@Override
	public Integer getNoSplPassNum(Long splId) throws BaseException {
		int noSplPassNum = 0;
    	if (StringUtils.isEmpty(splId)) {
			return 0;
		}
    	CapPayInfoQueryCondition capPayInfoQueryCondition = new CapPayInfoQueryCondition();
    	capPayInfoQueryCondition.setIsDel(0);
    	capPayInfoQueryCondition.setSplId(splId);
    	capPayInfoQueryCondition.setPayStsCdList(Arrays.asList("3","5"));
		List<CapPayInfoVO> capPayInfoVOS = this.searchList(capPayInfoQueryCondition);
		BaseLogUtils.newLogger("信审页面查询项目产品splId=" + splId + ",capPayInfoVOS=" + JSON.toJSONString(capPayInfoVOS)).info();
		if (CollectionUtils.isNotEmpty(capPayInfoVOS)) {
			noSplPassNum = capPayInfoVOS.size();
			List<Long> dtlIdList = new ArrayList<>();
			for (CapPayInfoVO capPayInfoVO : capPayInfoVOS) {
				if (StringUtils.isNotEmpty(capPayInfoVO.getPrjPrdDtlId())) {
					dtlIdList.add(capPayInfoVO.getPrjPrdDtlId());
				}
			}
			if (CollectionUtils.isNotEmpty(dtlIdList)) {
				PrjPrdMtgQueryCondition prdMtgQueryCondition = new PrjPrdMtgQueryCondition();
				prdMtgQueryCondition.setIdList(dtlIdList);
				prdMtgQueryCondition.setGuarStsCds(Arrays.asList("2","3","4"));
				BaseLogUtils.newLogger("信审页面查询抵押信息入参splId=" + splId + ",prdMtgQueryCondition=" + JSON.toJSONString(prdMtgQueryCondition)).info();
				List<PrjPrdMtgDTO> prjPrdMtgDTOS = projectApiService.searchPrjPrdMtgList(prdMtgQueryCondition, CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd());
				BaseLogUtils.newLogger("信审页面查询抵押信息splId=" + splId + ",prjPrdMtgDTOS=" + JSON.toJSONString(prjPrdMtgDTOS)).info();
				if (CollectionUtils.isNotEmpty(prjPrdMtgDTOS)) {
					noSplPassNum = capPayInfoVOS.size() - prjPrdMtgDTOS.size();
				}
			}
		}
		BaseLogUtils.newLogger("信审页面查询抵押信息splId:" + splId + ",noSplPassNum:" + noSplPassNum).info();
		return noSplPassNum;
	}

	@Override
	public Pager searchPayRecListPage(Pager page) throws BaseException {
		if (null == page) {
			page = new Pager();
			page.setCondition(new CapPayInfoQueryCondition());
		}
		CapPayInfoQueryCondition condition = (CapPayInfoQueryCondition) page.getCondition();
		condition.setSysCd(CurrentThreadContext.getCurrentSysCd());
		condition.setOrgCd(CurrentThreadContext.getCurrentOrgCd());
		condition.setUsrId(CurrentThreadContext.getCurrentUserId());
		BaseLogUtils.newServiceLogger("searchPayRecListPage Start page:" + JSON.toJSONString(page)).info();
		page = this.capPayInfoApiService.searchPayRecListPage(page);
		if (CollectionUtils.isNotEmpty(page.getResultList())) {
			List<CapPayInfoDTO> resultList = (List<CapPayInfoDTO>) page.getResultList();
			BaseLogUtils.newServiceLogger("searchPayRecListPage End resultList.size:" + resultList.size()).info();
			List<CapPayInfoVO> voList = CapPayInfoVOTransform.toVOList(resultList);
			this.setDictData(voList);
			page.setResultList(voList);
		}
		return page;
	}

	@Override
	public List<CapPayInfoVO> selectListByEnabledPaySchId(Long paySchId) throws BaseException {
		if (paySchId == null) return null;
		return CapPayInfoVOTransform.toVOList(this.capPayInfoApiService.selectListByEnabledPaySchId(paySchId));
	}

	@Override
	public void modifyPrjBscInfoForLcvCancel(Long capPayId) throws BaseException{
		CapPayInfoVO capPayInfoVO = this.selectById(capPayId);
		if(null != capPayInfoVO){
			PrjBscInfoVO prjBscInfoVO = this.prjBscInfoService.selectById(capPayInfoVO.getPrjId());
			if(null != prjBscInfoVO){
				prjBscInfoVO.setPrjStsCd("910170");
				this.prjBscInfoService.modify(prjBscInfoVO);
			}
		}
	}
}
